> For the complete documentation index, see [llms.txt](https://developers.bloomcredit.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.bloomcredit.io/recipes/v2.1/query-credit-data-using-python.md).

# Query Credit Data using Python

Learn how to install and use the Python SDK to interact with the Bloom API.

## Install the Python Bloom SDK

{% code title="Python, line 1" %}

```python
# pip install git+https://github.com/bloomcredit/bloomPy.git
```

{% endcode %}

Run in your terminal the following command to install the Bloom SDK using pip.

`pip3 install git+https://github.com/bloomcredit/bloomPy.git`

The SDK is open-source and available on [Github](https://github.com/bloomcredit/bloomPy)

## Import the SDK

{% code title="Python, line 3" %}

```python
from bloom import bloom
```

{% endcode %}

Load the Bloom SDK in your python module

## Load your credentials

{% code title="Python, lines 5-7" %}

```python
client_id = "<client_id>"
client_secret = "<client_secret>"
audience = "dev-api"
```

{% endcode %}

Enter here your Bloom API credentials client\_id and client\_secret. Also select the audience you want to use, here we will use our Sandbox environment.

Note: you can also use the following environment variables to store your credentials: `BLOOM_CLIENT_ID`, `BLOOM_CLIENT_SECRET`, `BLOOM_AUDIENCE`

If you don't have credentials yet, please \[Contact Us].(<https://bloomcredit.io/contact-us/>)

## Fetch your Auth Token

{% code title="Python, lines 10-15" %}

```python
auth_token, response = bloom.fetch_auth_token(
    audience=audience,
    client_id=client_id,
    client_secret=client_secret,
    grant_type="client_credentials"
)
```

{% endcode %}

Use the previously loaded credentials to fetch an Auth Token from the Bloom API. Use `client_credentials` as a grant\_type.

Note, you can also use the BLOOM\_GRANT\_TYPE environment variable as a value for the `grant_type` field.

## Fetch your Portfolio

{% code title="Python, lines 17-20" %}

```python
portfolio_id, response = bloom.get_portfolios(
   auth_token=auth_token,
   audience=audience
)
```

{% endcode %}

Using the `get_portfolios` function with your previously created `auth_token` This will return in the `portfolio_id` variable the correct id for your main portfolio.

## Build a Consumer Payload and Register

{% code title="Python, lines 22-38" %}

```python
consumer_info = {
   "ssn": "123456789",
   "city": "Scranton",
   "line1": "1725 Slough Avenue",
   "state_code": "PA",
   "zipcode": "18503",
   "date_of_birth": "1964-03-15",
   "first_name": "Michael",
   "last_name": "Scott",
   "address_primary": True
}

consumer_id, response = bloom.register_consumer(
   consumer_info=consumer_info,
   auth_token=auth_token,
   audience=audience
)
```

{% endcode %}

First build a payload containing all the necessary information for the consumer you want to register, then use this data to send an API call to the Bloom API. The id of the newly registered consumer will be sent back and stored in the `consumer_id` variable.

## Order a credit data report for your consumer

{% code title="Python, lines 40-46" %}

```python
credit_order, response = bloom.order_credit_data(
   consumer_id=consumer_id,
   portfolio_id=portfolio_id,
   sku="equifax-silver-soft-fico-internet",
   auth_token=auth_token,
   audience=audience
)
```

{% endcode %}

Using your previously registered consumer and portfolio, order a new credit data report from Bloom. Indicate in the sku a the chosen report to be created.

The id of the order will be returned in the `credit_order` variable.

## Fetch the credit data

{% code title="Python, lines 48-53" %}

```python
credit_data, response = bloom.get_credit_data(
   order_id=credit_order,
   auth_token=auth_token,
   outfile="credit_data.json",
   audience=audience
)
```

{% endcode %}

Once the credit data is generated, fetch the result using the `get_credit_data` function. The result payload will be returned in the `credit_data` variable as well as stored in the file path specified in the `outfile` parameter.

## All done!

{% code title="Python, lines 1-53" %}

```python
# pip install git+https://github.com/bloomcredit/bloomPy.git

from bloom import bloom

client_id = "<client_id>"
client_secret = "<client_secret>"
audience = "dev-api"

# Fetch Token ignoring credentials stored in the .env file
auth_token, response = bloom.fetch_auth_token(
    audience=audience,
    client_id=client_id,
    client_secret=client_secret,
    grant_type="client_credentials"
)

portfolio_id, response = bloom.get_portfolios(
   auth_token=auth_token,
   audience=audience
)

consumer_info = {
   "ssn": "123456789",
   "city": "Scranton",
   "line1": "1725 Slough Avenue",
   "state_code": "PA",
   "zipcode": "18503",
   "date_of_birth": "1964-03-15",
   "first_name": "Michael",
   "last_name": "Scott",
   "address_primary": True
}

consumer_id, response = bloom.register_consumer(
   consumer_info=consumer_info,
   auth_token=auth_token,
   audience=audience
)

credit_order, response = bloom.order_credit_data(
   consumer_id=consumer_id,
   portfolio_id=portfolio_id,
   sku="equifax-silver-soft-fico-internet",
   auth_token=auth_token,
   audience=audience
)

credit_data, response = bloom.get_credit_data(
   order_id=credit_order,
   auth_token=auth_token,
   outfile="credit_data.json",
   audience=audience
)
```

{% endcode %}

You can now use the **Bloom API** using the Python SDK!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.bloomcredit.io/recipes/v2.1/query-credit-data-using-python.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
