SDKs overview
OpenSanctions provides a platform for accessing structured data on sanctioned entities, politically exposed persons (PEPs), and other high-interest individuals and organizations. To facilitate integration with its API and data feeds, OpenSanctions offers official and community-contributed Software Development Kits (SDKs) and libraries. These tools abstract away the complexities of direct HTTP requests, authentication, and response parsing, allowing developers to focus on application logic rather than API mechanics. While the core OpenSanctions API is RESTful and accessible via standard HTTP clients, SDKs can accelerate development by providing idiomatic interfaces for specific programming languages.
The primary functions supported by these SDKs typically include:
- Querying entities: Searching for individuals or organizations based on various criteria such as name, country, or identifiers.
- Retrieving entity details: Fetching comprehensive profiles for specific entities, including associated names, dates of birth, addresses, and relationships.
- Data processing: Tools or utilities for handling the bulk data downloads provided by OpenSanctions, which can be in formats like JSON or CSV.
- Helper functions: Utilities for tasks like data normalization, matching, or interpreting specific data fields from the OpenSanctions dataset.
Developers integrating OpenSanctions data can choose between using these SDKs for a higher-level abstraction or interacting directly with the OpenSanctions API endpoints using a generic HTTP client library, depending on their project requirements and preferred level of control.
Official SDKs by language
OpenSanctions maintains official client libraries designed to provide robust and up-to-date access to its services. These SDKs are typically developed and supported directly by the OpenSanctions team, ensuring compatibility with the latest API versions and data structures. The official offerings focus on languages commonly used in data processing, compliance, and web development environments.
The following table outlines the key official SDKs available:
| Language | Package/Module | Installation Command | Maturity | Description |
|---|---|---|---|---|
| Python | opensanctions |
pip install opensanctions |
Stable | A comprehensive library for interacting with the OpenSanctions API, processing data, and performing entity matching within Python applications. |
| Go | github.com/opensanctions/go-opensanctions |
go get github.com/opensanctions/go-opensanctions |
Stable | Provides Go language bindings for querying the OpenSanctions API and handling data structures, suitable for high-performance backend services. |
Installation
Installing OpenSanctions SDKs is typically straightforward, following standard package management practices for each respective language. The instructions below cover the official libraries.
Python SDK Installation
The Python SDK is distributed via PyPI, the Python Package Index. Installation is performed using pip, Python's package installer.
pip install opensanctions
It is recommended to use a Python virtual environment to manage dependencies for your project.
Go SDK Installation
The Go SDK is available through Go Modules. You can add it to your project using the go get command.
go get github.com/opensanctions/go-opensanctions
This command will download the module and add it to your go.mod file, managing its dependencies automatically.
Quickstart example
The following examples demonstrate basic usage of the official OpenSanctions SDKs to perform common tasks, such as querying for an entity. For full API documentation and advanced usage patterns, refer to the OpenSanctions developer documentation.
Python Quickstart: Searching for an entity
This example shows how to use the Python SDK to search for a specific entity by name and print basic information about the results.
import os
from opensanctions import OpenSanctions
# Replace with your actual API key
# It's recommended to load this from an environment variable
api_key = os.environ.get("OPENSANCTIONS_API_KEY", "YOUR_API_KEY")
os = OpenSanctions(api_key=api_key)
query = "Vladimir Putin"
results = os.search_entities(query=query)
print(f"Searching for: {query}")
if results and results.get("results"):
for entity in results["results"]:
print(f" ID: {entity.get('id')}")
print(f" Name: {entity.get('name')}")
print(f" Schema: {entity.get('schema')}")
print(f" Countries: {', '.join(entity.get('countries', []))}")
print("---")
else:
print("No results found.")
To run this example, ensure you have installed the Python SDK and replaced "YOUR_API_KEY" with your actual OpenSanctions API key, or set it as an environment variable named OPENSANCTIONS_API_KEY.
Go Quickstart: Searching for an entity
This Go example demonstrates how to make a basic search query using the go-opensanctions library and process the returned entities.
package main
import (
"context"
"fmt"
"log"
"os"
opensanctions "github.com/opensanctions/go-opensanctions"
)
func main() {
// Replace with your actual API key
// It's recommended to load this from an environment variable
apiKey := os.Getenv("OPENSANCTIONS_API_KEY")
if apiKey == "" {
apiKey = "YOUR_API_KEY"
log.Println("Warning: Using placeholder API key. Set OPENSANCTIONS_API_KEY environment variable.")
}
client := opensanctions.NewClient(apiKey)
query := "Maria Zakharova"
params := &opensanctions.SearchParams{
Query: query,
}
resp, err := client.SearchEntities(context.Background(), params)
if err != nil {
log.Fatalf("Error searching entities: %v", err)
}
fmt.Printf("Searching for: %s\n", query)
if resp != nil && len(resp.Results) > 0 {
for _, entity := range resp.Results {
fmt.Printf(" ID: %s\n", entity.ID)
fmt.Printf(" Name: %s\n", entity.Name)
fmt.Printf(" Schema: %s\n", entity.Schema)
fmt.Printf(" Countries: %v\n", entity.Countries)
fmt.Println("---")
}
} else {
fmt.Println("No results found.")
}
}
To execute this Go example, ensure you have the go-opensanctions module installed and provide your OpenSanctions API key, either directly or via the OPENSANCTIONS_API_KEY environment variable.
Community libraries
Beyond the officially supported SDKs, the OpenSanctions ecosystem benefits from community-contributed libraries and tools. These libraries often extend functionality, provide integrations with specific frameworks, or offer support for languages not covered by official SDKs. While community libraries may not carry the same level of direct support or guaranteed compatibility as official offerings, they can be valuable resources for developers.
As of the last review, the OpenSanctions documentation primarily highlights its official Python and Go SDKs. Developers interested in contributing or finding community-developed tools for other languages are encouraged to explore public code repositories, such as OpenSanctions's GitHub organization, or relevant developer forums. Community contributions often emerge organically based on developer needs and preferences.
When considering a community-developed library, it is advisable to assess its:
- Maintenance status: Check the last commit date, open issues, and pull requests to gauge active development.
- Documentation: Ensure there is sufficient documentation to understand how to use the library effectively.
- License: Verify the license is compatible with your project's requirements.
- Community support: Look for signs of an active community, such as forum discussions or issue tracking engagement.
Direct interaction with the OpenSanctions REST API using generic HTTP clients (e.g., requests in Python, axios in JavaScript, fetch in web browsers) remains a viable option for languages without dedicated SDKs, providing maximum flexibility and control over the integration process.