> Call the Check Share Code API from Python: authentication, requesting a check, and reading the response.

Web version: https://checksharecode.co.uk/tutorials/quickstart-python · Sign up: https://checksharecode.co.uk/signup?ref=md · Last updated: 2026-11-23

[← Back to docs](https://checksharecode.co.uk/docs)

# Quickstart: Python

Sign up, mint a test key, send your first check from Python.

## 1\. Install httpx

Any HTTP client works. We use `httpx` for the timeouts and pleasant defaults.

```
pip install httpx
```

## 2\. Send a request

```
import os
import httpx

RTW_KEY = os.environ["RTW_KEY"]  # rtw_test_… or rtw_live_…

resp = httpx.post(
    "https://api.checksharecode.co.uk/v1/check/right-to-work",
    json={
        "share_code": "AA1AA1AA1",   # sandbox: ACCEPTED fixture
        "date_of_birth": "1990-01-01",
        "company_name": "Acme Ltd",
    },
    headers={"authorization": f"Bearer {RTW_KEY}"},
    timeout=60.0,
)

if resp.status_code != 200:
    err = resp.json()["error"]
    raise RuntimeError(f"{err['code']}: {err['message']}")

data = resp.json()
print(data["outcome"], data["name"], data["expiry_date"])
```

## 3\. Handle the photo and PDF

`photo_data_url` and `pdf_data_url` are base64 data URLs. Decode and persist if you need a record (subject to your retention rules; we delete our copy within 7 days).

```
import base64
from urllib.parse import urlparse

if data["pdf_data_url"]:
    # "data:application/pdf;base64,JVBE..."
    _, b64 = data["pdf_data_url"].split(",", 1)
    with open(f"{data['reference']}.pdf", "wb") as f:
        f.write(base64.b64decode(b64))
```

## 4\. Timeouts

A live check usually takes 15 to 40 seconds. Use a 60 second read timeout. The server returns 504 TIMEOUT if gov.uk takes longer than its own internal budget. It is safe to retry.
