---
title: "BIN Lookup API Python Guide"
description: "Call the BIN Lookup API from Python with requests. Handle current error codes and send a batch lookup."
section: "Guides"
url: "https://binlookupapi.com/docs/guides/python/"
markdown_url: "https://binlookupapi.com/docs/guides/python.md"
---
# BIN lookup with Python

This page uses Python 3 and the `requests` library. Create an API key in the [quickstart](/docs/quickstart/).

```bash
pip install requests
export BINLOOKUP_API_KEY="your_key_here"
```

## Look up one BIN

```python
import os
import requests

API_KEY = os.environ["BINLOOKUP_API_KEY"]
URL = "https://api.binlookupapi.com/v1/bin"

response = requests.post(
    URL,
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    },
    json={"number": 42467101},
    timeout=30,
)
payload = response.json()

if response.status_code == 200:
    data = payload["data"]
    print(data["scheme"], data["issuer"]["name"])
    print("Remaining:", response.headers["X-Quota-Remaining"])
elif response.status_code == 401:
    raise SystemExit("The API key is missing or not valid.")
elif response.status_code == 403:
    raise SystemExit(f"{payload.get('error')}: {payload.get('message')}")
elif response.status_code == 404:
    raise SystemExit("The BIN is not in the data.")
elif response.status_code == 429:
    raise SystemExit("The daily quota is used.")
elif response.status_code == 400:
    raise SystemExit(payload.get("message", "The request is not valid."))
else:
    raise SystemExit(f"The API returned HTTP {response.status_code}.")
```

`data` contains the fields in the [API reference](/docs/api-reference/#response-fields). On BLAPI-150KPM and above, read `payload["meta"]["longer_bin_available"]`. On lower plans, `meta` is absent.

HTTP 403 is `FORBIDDEN` or `FEATURE_NOT_AVAILABLE`.

## Look up many BINs

`POST /v1/bins` accepts 1 to 2,000 values. It requires BLAPI-500KPM, or a test-mode organisation. Each value uses one lookup.

```python
response = requests.post(
    "https://api.binlookupapi.com/v1/bins",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    },
    json={"numbers": [400062, "400597", 99999999]},
    timeout=60,
)
payload = response.json()

if response.status_code == 403 and payload.get("error") == "FEATURE_NOT_AVAILABLE":
    raise SystemExit("Batch lookup needs the BLAPI-500KPM plan.")

response.raise_for_status()

for item in payload["results"]:
    if "data" in item:
        print(item["number"], item["data"]["scheme"])
    else:
        print(item["number"], item["error"])
```

If the batch is larger than the remaining quota, the status is 429 and no quota is used. Read `X-Quota-Remaining` and split the list. See [Batch lookups](/docs/batch-lookups/).

## Related pages

- [JavaScript guide](/docs/guides/javascript/)
- [PHP guide](/docs/guides/php/)
- [API reference](/docs/api-reference/)
- [API keys](/docs/api-keys/)
- [Billing](/docs/subscriptions/)
