I want to retrieve data from OpenSanctions Database using Python, but I'm not sure how to
use their API.
I have already created an
API key: e8e46841798b13ecb2a416cfcd98e3f0
My goal is to fetch 100 entities from the "People" dataset. I tried accessing the API using the documentation at OpenSanctions Default Dataset, but
I received a 404 error with no details found.
Can you show me the correct way to use the API in Python to get this data?
import requests
# Define your API key and the endpoint
api_key = 'e8e46841798b13ecb2a416cfcd98e3f0'
url = '' # Corrected search endpoint
# Set the headers with the API key
headers = {
'Authorization': f'Bearer {api_key}',
}
# Define the parameters for your search request
params = {
'schema': 'Person', # Use 'schema' instead of 'entity_type'
'limit': 100, # Limit to 100 records
'q': '' # Optionally add a search query, e.g., 'q': 'John Doe'
}
# Make the GET request to the API
response = requests.get(url, headers=headers, params=params)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
# Print the returned data
print(data)
else:
print(f"Error: {response.status_code} - {response.text}")
Sandhiya PriyaPosted Nov 6, 2025, 8:44 AM
To retrieve data from the OpenSanctions API, you need to make sure you're using the correct endpoint and query parameters as specified in their documentation. The 404 error typically means that the endpoint you were trying to reach doesn't exist or was incorrectly specified.
Here’s a corrected version of your script. From the OpenSanctions API documentation, the endpoint for querying people is typically structured like this:
Steps to retrieve data:
Ensure the endpoint is correct.
The
schemaor entity type should correspond to the dataset you're interested in. In this case, you're looking for the "People" dataset, which might not be a direct parameter to pass, but filtering on the type of entity should work.Set the proper query parameters such as
qfor searching or leaving it blank for general results.Here’s an updated Python script to fetch 100 people entities:
Key Points:
Endpoint: The endpoint for fetching entities is
https://api.opensanctions.org/entities.Schema Filter: By setting
'schema': 'Person', you ensure that the API returns people-related data.Query Parameters:
'limit': 100ensures you get only 100 results.'q'is optional; you can use it to filter by name or any other search term.Debugging the Error:
Check the URL: Ensure the URL is exactly
https://api.opensanctions.org/entities.Authorization: Ensure that your API key is correct and has access to the API.
Schema: Double-check the API documentation to ensure that
'Person'is the correct schema name (sometimes they could have more detailed filtering parameters).If this script still results in a 404 error or if there are any further issues, you should consult the OpenSanctions API documentation directly for any potential changes to the endpoint or authentication method.