Python quickstart
4 min read Updated October 21, 2026
SDK status
The Python SDK is a source preview at github.com/compliancegrid-ai/compliancegrid-python. It is not yet published to PyPI, so pip install compliancegrid does not work. Use requests (or httpx).
Calling the API
python
import os, requests
key = os.environ['CG_API_KEY'] # cg_sk_ (sandbox) or cg_pk_ (production)
host = ('https://sandbox.api.compliancegrid.ai' if key.startswith('cg_sk_')
else 'https://api.compliancegrid.ai')
headers = {'x-api-key': key}
res = requests.post(
host + '/v1/compliance/restricted-party-screening',
headers=headers,
json={'parties': [{'name': 'Huawei Technologies', 'country': 'CN'}]},
)
data = res.json()['data']
print(data['overallResult']) # 'POTENTIAL_MATCH'
print(data['totalMatches'])
for match in data['results'][0]['matches'][:3]:
print(match['listName'], match['matchedName'], match['matchScore'])HS code search
python
res = requests.get(host + '/v1/hs/search', headers=headers, params={'q': 'cotton fabric', 'limit': 5})
for hit in res.json()['data']['results']:
print(hit['htsNumber'], hit['description'][:60])Error handling
Check res.status_code. A 429 carries a Retry-After header. Authentication errors are {'error': 'invalid_api_key', 'message': ...}; all other errors are {'success': False, 'error': {'code', 'message', 'details'}}. Retry 429 and 5xx responses with exponential backoff yourself.
Was this article helpful?