OpenSanctions, bring your own key: the hosted yente matching API
(POST /match/{dataset}), or a self-hosted yente via base-url. It
screens against OpenSanctions' merged dataset (hundreds of sources,
plus PEPs in default).
Screening never decides. A result is "possible-match" or
"no-match", and a person must review every possible match.
Licensing: OpenSanctions data is published under CC BY-NC 4.0. Non-commercial use is free; commercial use needs a license (the hosted API is a paid service with a trial; bulk data for business use needs a data license). See https://www.opensanctions.org/licensing/.
Results are ScreenResult records. sources names the dataset
searched.
Context Vars
opensanctions.api-keyopensanctions.base-urlopensanctions.dataset
Values
KINDS
KINDS: Map {
Person: "individual",
Organization: "entity",
Company: "entity",
LegalEntity: "entity",
PublicBody: "entity",
Vessel: "vessel",
Airplane: "aircraft"
}
REVIEW_NOTICE
REVIEW_NOTICE: Str "Automated screening result. Every possible match must be reviewed by a person before any decision; a no-match only means no entry scored above the threshold on the dataset searched."
SCHEMAS
SCHEMAS: Map {
individual: "Person",
entity: "Organization",
vessel: "Vessel",
aircraft: "Airplane"
}
Functions
match-body
fn (name: Str, opts: Map): Map
The /match request body for one query (pure): {queries: {q: {schema, properties}}}. name always; birthDate and
nationality (Person) or country (others) only when given.
Example
::opensanctions/match-body("John Doe", {dob: "1975-04-21", country: "US", kind: "individual"})
// {queries: {q: {schema: "Person", properties: {name: ["John Doe"], birthDate: ["1975-04-21"], nationality: ["us"]}}}}
match-headers
fn (key: Str?): Map
The /match request headers (pure): Authorization: ApiKey ... only
when there is a key, since a self-hosted yente may need none.
Example
::opensanctions/match-headers(null) // {Content-Type: "application/json", Accept: "application/json"}
match-query
fn (opts: Map): Str
The /match query string (pure): threshold, limit, algorithm and
topics only when set in opts, and include_dataset from
opts.include-datasets.
Example
::opensanctions/match-query({threshold: 0.8, limit: 5}) // "?threshold=0.8&limit=5"
::opensanctions/match-query({topics: ["sanction"]}) // "?topics=sanction"
::opensanctions/match-query({}) // ""
match-url
fn (base-url: Str, dataset: Str, opts: Map): Str
{base-url}/match/{dataset}{query} with the dataset path-encoded
(pure).
Example
::opensanctions/match-url("https://api.opensanctions.org", "sanctions", {limit: 5}) // "https://api.opensanctions.org/match/sanctions?limit=5"
notice-for
fn (sources: Vec): Str
REVIEW_NOTICE followed by what was searched, so the notice says what a
"no-match" covers wherever it is read.
Example
notice ::opensanctions/notice-for([{list: "OpenSanctions (sanctions)"}])
ends-with(notice, "Searched: OpenSanctions (sanctions).") // true
parse-response
fn (body: Any, name: Str, opts: Map, base-url: Str): ScreenResult
Turn a /match response body into a ScreenResult (pure).
Example
body {responses: {q: {results: [{id: "NK-abc", caption: "John Doe", schema: "Person", score: 0.91, match: true, properties: {}}]}}}
out ::opensanctions/parse-response(body, "John Doe", {dataset: "sanctions"}, "https://api.opensanctions.org")
out.status // "possible-match"
out.review-required // true
length(out.matches) // 1
first(out.sources).dataset // "sanctions"
round4
fn (x: Any): Dec
Round a number to four decimal places.
Example
::opensanctions/round4(div(2, 3)) // 0.6667
::opensanctions/round4(1) // 1.0
screen
fn (name: Str): ScreenResult
fn (name: Str, opts: Map): ScreenResult
Screen a name with the OpenSanctions matching API. opts: dob,
country, kind, threshold (OpenSanctions' default 0.7),
limit, algorithm, topics (e.g. ["sanction"]),
include-datasets, plus credentials and settings: api-key,
base-url, dataset ("default", or "sanctions" for sanctions
only). The hosted API needs a key. A per-call base-url only uses an
api-key from the same opts; without one, no key is sent.
Sends the queried name, date of birth and country to OpenSanctions.
Example
result ::opensanctions/screen("Aleksandr Lukashenko", {kind: "individual", dataset: "sanctions"})
to-match
fn (r: Map, base-url: Str): Match
Turn one OpenSanctions scored result into a Match (pure). The entry
carries source: "opensanctions", the OpenSanctions id, the datasets as
programs, and the score explanations.
Example
r {id: "NK-abc", caption: "John Doe", schema: "Person", score: 0.91, match: true, datasets: ["us_ofac_sdn"], properties: {name: ["John Doe", "Johnny Doe"]}}
m ::opensanctions/to-match(r, "https://api.opensanctions.org")
m.status // "possible-match"
m.score // 0.91
m.entry.kind // "individual"
m.entry.aliases // ["Johnny Doe"]
Types
Match
Match type {
status: Str,
score: Dec,
name-score: Dec,
matched-name: Str,
matched-field: Str,
matched-fields: Vec<Str>,
explanation: Vec<Str>,
entry: Map
}
One possible match.
Fields
status— always"possible-match": review itscore— OpenSanctions' score in [0, 1]name-score— the same score; OpenSanctions gives only onematched-name— OpenSanctions' caption for the entitymatched-field— always"name"matched-fields— every field that contributedexplanation— OpenSanctions' score and its feature explanations, for the reviewerentry— the entity:{source, list, id, kind, name, aliases, dobs, nationalities, programs, addresses, remarks, url}
ScreenResult
ScreenResult type {
status: Str,
review-required: Bool,
notice: Str,
query: Map,
threshold: Dec,
matches: Vec<Match>,
sources: Vec<Map>,
warnings: Vec<Str>,
candidates: Int
}
The answer to a screen call. A person must review every match.
Fields
status—"possible-match"when any match scored at or above the threshold, else"no-match"; never a final decisionreview-required— true wheneverstatusis"possible-match"notice— the human-review notice, ending with the dataset searchedquery— the name and options screenedthreshold— the threshold usedmatches—Matchrecords, best firstsources— what was searched:{source, list, dataset}. Nothing else was searchedwarnings— always empty todaycandidates— how many results OpenSanctions returned