{"id":51028818,"url":"https://github.com/jm-rivera/resolvekit","last_synced_at":"2026-06-21T22:01:55.595Z","repository":{"id":364132370,"uuid":"1266219096","full_name":"jm-rivera/resolvekit","owner":"jm-rivera","description":"Entity and place resolution system that maps messy place/entity strings and codes to canonical entities","archived":false,"fork":false,"pushed_at":"2026-06-11T19:51:25.000Z","size":4146,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-11T20:13:12.708Z","etag":null,"topics":["data-commons","disambiguation","entity-resolution","geocoding","iso-codes","normalization","offline","place-names","python"],"latest_commit_sha":null,"homepage":"https://jm-rivera.github.io/resolvekit/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jm-rivera.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-11T12:25:08.000Z","updated_at":"2026-06-11T13:53:45.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jm-rivera/resolvekit","commit_stats":null,"previous_names":["jm-rivera/resolvekit"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/jm-rivera/resolvekit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jm-rivera%2Fresolvekit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jm-rivera%2Fresolvekit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jm-rivera%2Fresolvekit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jm-rivera%2Fresolvekit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jm-rivera","download_url":"https://codeload.github.com/jm-rivera/resolvekit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jm-rivera%2Fresolvekit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34627192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-commons","disambiguation","entity-resolution","geocoding","iso-codes","normalization","offline","place-names","python"],"created_at":"2026-06-21T22:01:54.750Z","updated_at":"2026-06-21T22:01:55.586Z","avatar_url":"https://github.com/jm-rivera.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# resolvekit\n\n[![PyPI version](https://img.shields.io/pypi/v/resolvekit.svg)](https://pypi.org/project/resolvekit/)\n[![conda-forge version](https://img.shields.io/conda/vn/conda-forge/resolvekit.svg)](https://anaconda.org/conda-forge/resolvekit)\n[![Python versions](https://img.shields.io/pypi/pyversions/resolvekit.svg)](https://pypi.org/project/resolvekit/)\n[![License: MIT](https://img.shields.io/pypi/l/resolvekit.svg)](https://github.com/jm-rivera/resolvekit/blob/main/LICENSE)\n[![Tests](https://github.com/jm-rivera/resolvekit/actions/workflows/test.yml/badge.svg)](https://github.com/jm-rivera/resolvekit/actions/workflows/test.yml)\n[![Docs](https://img.shields.io/badge/docs-jm--rivera.github.io-blue.svg)](https://jm-rivera.github.io/resolvekit/)\n[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\nResolve messy place and entity strings — and codes — to canonical entity IDs, offline and deterministically. Feed it `\"Brasil\"`, `\"Cote dIvoire\"`, or `\"Republic of Korea\"` and get back `country/BRA`, `country/CIV`, `country/KOR`.\n\n- **Offline and deterministic.** No network call, no LLM, no external service at resolution time. The same input gives the same output, today and next year.\n- **Countries to cities to organizations.** Resolve countries, UN M.49 regions, continents, sub-national admin levels 1–5, cities, and organizations through one pipeline. Most alternatives stop at countries.\n- **Typo- and alias-tolerant.** Exact-code and exact-name matching, full-text search, fuzzy matching, and typo correction, with a calibrated confidence score on every result.\n- **Built for tabular data.** `bulk()` cleans a whole pandas or polars column in one call, deduplicating repeated values.\n- **A graph, not a lookup table.** List the members of the EU, NATO, or OECD, check membership, convert between code systems, and query it all as of a past date.\n\n## Install\n\n```bash\n# with uv\nuv add resolvekit                  # Python \u003e= 3.12\nuv add \"resolvekit[pandas]\"        # add the pandas integration for bulk()\n\n# with pip\npip install resolvekit\npip install \"resolvekit[pandas]\"\n```\n\nCountry, region, continent, and organization data ships in the wheel and works offline immediately. Sub-national admin levels and cities are fetched on first use — see [the docs](https://jm-rivera.github.io/resolvekit/).\n\n## Quickstart\n\n```python\nimport resolvekit as rk\n\nrk.resolve_id(\"United States\")        # \"country/USA\"\nrk.resolve(\"Germany\", to=\"iso3\")      # \"DEU\"\nrk.resolve(\"Japan\", to=\"flag\")        # \"🇯🇵\"\nrk.resolve(\"Tanzania\", to=\"dcid\")     # \"country/TZA\"\n```\n\n`to=` pivots a resolved entity to `iso2`, `iso3`, `name`, `flag`, `dcid`, `wikidata`, and other code systems.\n\nClean a DataFrame column in one call. `bulk()` deduplicates internally, so a 10,000-row column with 50 distinct values runs 50 resolutions, not 10,000:\n\n```python\nimport pandas as pd\nimport resolvekit as rk\n\ndf = pd.DataFrame({\"country\": [\"United States\", \"Brasil\", \"Cote dIvoire\", \"n/a\"]})\ndf[\"iso3\"] = rk.bulk(values=df[\"country\"], to=\"iso3\")\n#       country  iso3\n# United States   USA\n#        Brasil   BRA\n#  Cote dIvoire   CIV\n#           n/a  None\n```\n\n## What you can do with it\n\n### Every result carries a calibrated confidence score\n\n`confidence` is a calibrated probability, not a raw similarity score — `0.93` means the pipeline estimates roughly a 93% chance the match is correct. A code match and a fuzzy name match are on the same scale:\n\n```python\nr = rk.resolve(\"US\")\nr.entity_id     # \"country/USA\"\nr.confidence    # 0.951\nr.match_tier    # \"exact_code\"\n```\n\nCall `r.explain(verbosity=\"full\").as_text()` for a scorecard of which matchers fired, what they matched, and why this candidate won. It renders to text, Markdown, or JSON.\n\n### It abstains instead of guessing\n\nWhen two candidates score too close to separate, the result is ambiguous — `confidence` is `None`, and each candidate carries its own score:\n\n```python\nr = rk.resolve(\"Congo\")\nr.is_ambiguous                          # True\n[(c.entity_id, round(c.confidence, 3)) for c in r.candidates[:2]]\n# [(\"country/COD\", 0.908), (\"country/COG\", 0.908)]\n```\n\n`resolve_id()` raises `AmbiguousResolutionError` by default; pass `on_ambiguous=\"null\"` for `None` or `\"best\"` to take the top candidate. Placeholder inputs like `\"n/a\"` or `\"unknown\"` short-circuit to no-match before scoring.\n\n### Query the graph — including as of a past date\n\nEntities carry typed, time-aware relations. Ask who belongs to a group, what a region contains, and what either looked like on a given date:\n\n```python\nfrom datetime import date\n\nr = rk.default()\n\nr.members_of(\"EU\", as_codes=\"iso3\")                          # 27 codes\nr.is_member(\"United Kingdom\", \"EU\")                          # False — left in 2020\nr.is_member(\"United Kingdom\", \"EU\", as_of=date(2018, 1, 1))  # True\nr.within(\"Eastern Africa\", entity_type=\"geo.country\", to=\"iso3\")\n# ['BDI', 'COM', 'DJI', 'ERI', 'ETH', 'KEN', 'MDG', 'MOZ', 'MUS',\n#  'MWI', 'MYT', 'RWA', 'SOM', 'SSD', 'SYC', 'TZA', 'UGA', 'ZMB', 'ZWE']\n```\n\n`as_of` drops candidates outside their existence window before scoring — it's a hard filter, not a score penalty.\n\n### Extract entities from free text\n\n`parse()` scans text with an Aho-Corasick dictionary pass, then runs the same resolution pipeline on each span. No NER model, no network call (needs `pip install \"resolvekit[parsing]\"`):\n\n```python\nimport resolvekit as rk\n\nfor e in rk.parse(\"Leaders from Kenya, Uganda and the United States met to discuss trade.\"):\n    if e.entity_id:\n        print(f\"{e.surface!r} [{e.start}:{e.end}] -\u003e {e.entity_id} ({e.confidence:.2f})\")\n# 'Kenya' [13:18] -\u003e country/KEN (0.91)\n# 'Uganda' [20:26] -\u003e country/UGA (0.91)\n# 'the United States' [31:48] -\u003e country/USA (0.91)\n```\n\n`parse_bulk()` runs over a list or Series and tags each span with its source row index.\n\n### Bring your own data\n\n`Resolver.from_records()` builds a resolver from a list of dicts, a DataFrame, or a CSV — no schema, no server:\n\n```python\nfrom resolvekit import Resolver\n\nr = Resolver.from_records(\n    [{\"id\": \"w1\", \"label\": \"Widget\", \"sku\": \"abc\"},\n     {\"id\": \"w2\", \"label\": \"Gadget\", \"sku\": \"xyz\"}],\n    domain=\"custom\", name=\"label\", id=\"id\", codes=[\"sku\"],\n)\nr.resolve(\"Widget\").entity_id   # \"custom/w1\"\nr.entity(sku=\"abc\").entity_id   # \"custom/w1\"\n```\n\n`Resolver.augment()` joins your own columns onto an existing resolver's entities by code, attaching attributes without a rebuild and reporting what linked, what was minted, and what was skipped.\n\n## How it compares\n\nresolvekit is benchmarked against eight other resolvers on a public, reproducible suite — run it yourself with `uv run python -m benchmarks`. Methodology and per-dataset numbers are in [benchmarks/README.md](https://github.com/jm-rivera/resolvekit/blob/main/benchmarks/README.md); the figures below are from the committed 2026-06-10 run. A dash means the tool was skipped because the dataset is outside its scope, not that it scored zero.\n\n| tool | offline | entity types | `countries_en` | `countries_multilingual` | `admin` | `cities` |\n|---|---|---|---|---|---|---|\n| **resolvekit** | yes | country, admin1–5, city, continent, org | **0.793** | 0.632 | **0.935** | **0.858** |\n| **resolvekit** (typed) | yes | same, with type hints | **0.794** | 0.614 | **0.977** | **0.862** |\n| hdx_python_country | yes | country | 0.642 | 0.565 | — | — |\n| countryguess | yes | country | 0.675 | 0.512 | — | — |\n| country_converter | yes | country | 0.566 | 0.419 | — | — |\n| geonamescache | yes | country, city | 0.057 | 0.148 | — | 0.000 |\n| rapidfuzz_dict | yes | country | 0.469 | 0.370 | — | — |\n| pycountry | yes | country | 0.099 | 0.143 | — | — |\n| data_commons_resolve | no | country, admin1–2, city | 0.625 | **0.827** | 0.598 | 0.502 |\n\nThe lead is widest on sub-national data. Six of the eight competitors are country-only and can't answer admin or city queries at all. On `cities`, resolvekit scores 0.858 against data_commons_resolve's 0.502 and geonamescache's 0.000; on `admin`, 0.935 against data_commons_resolve's 0.598. resolvekit is also the only tool that emits a calibrated confidence score (ECE 0.043 on the geo eval set).\n\n## How it works\n\n**The data.** resolvekit is built from public authority datasets — [Data Commons](https://datacommons.org/), ISO 3166, the UN M.49 standard, Wikidata, and World Bank/UN statistical groupings. Each entity gets one stable ID (countries reuse the Data Commons dcid, so `country/DEU` is the same key Data Commons uses) plus codes across dozens of systems: ISO 2/3/numeric, Wikidata, GND, VIAF, OpenStreetMap, IOC, and more. Names and codes drift over time; the ID stays fixed. The dataset is compiled into SQLite files that ship on disk, so resolution never makes a network call.\n\n**The graph.** Those entities are nodes in a graph, not rows in a flat code table. A small set of typed, time-aware edges — `member_of`, `contained_in`, `subsidiary_of` — connect them, each carrying a `[valid_from, valid_until)` validity window. That structure answers questions a code-conversion library can't: which countries were in the EU on a given date, what a region contains, which group an organization belongs to. It's a small, fixed graph for entity relations — there's no query language, just the membership and containment methods on `Resolver`.\n\n**Resolution.** A query is normalized, then run through a cascade of matchers, cheapest first — exact code, exact name, full-text search, fuzzy edit distance, then SymSpell typo correction — stopping once a confident match is found. Each candidate is scored by a calibrated model that folds match tier, edit distance, query length, and entity prominence into one confidence value, so a code match and a fuzzy name match sit on the same scale. The result is `resolved` when the top candidate clears the threshold and leads the runner-up by a margin, `ambiguous` when two are too close to separate, and `no_match` when nothing clears it.\n\nCountry, region, continent, and organization modules ship in the wheel; sub-national admin levels and cities are separate packs fetched on demand. See [How resolution works](https://jm-rivera.github.io/resolvekit/explanation/how-resolution-works/), [The entity graph](https://jm-rivera.github.io/resolvekit/explanation/knowledge-graph/), and [Offline-first and the data-pack split](https://jm-rivera.github.io/resolvekit/explanation/offline-and-data-packs/).\n\n## Documentation\n\nFull documentation — tutorial, how-to guides, API reference, and design notes — lives at **[jm-rivera.github.io/resolvekit](https://jm-rivera.github.io/resolvekit/)**.\n\n- [Install](https://jm-rivera.github.io/resolvekit/getting-started/install/)\n- [Your first resolution](https://jm-rivera.github.io/resolvekit/getting-started/first-resolution/) (tutorial)\n- [How-to guides](https://jm-rivera.github.io/resolvekit/how-to/clean-a-dataframe-column/)\n- [API reference](https://jm-rivera.github.io/resolvekit/reference/api/)\n- [How resolution works](https://jm-rivera.github.io/resolvekit/explanation/how-resolution-works/)\n- [Roadmap](https://jm-rivera.github.io/resolvekit/roadmap/)\n\n## License\n\nMIT — see [LICENSE](https://github.com/jm-rivera/resolvekit/blob/main/LICENSE). Bundled data is covered under multiple licenses; see [NOTICE.md](https://github.com/jm-rivera/resolvekit/blob/main/src/resolvekit/NOTICE.md) for third-party data attributions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjm-rivera%2Fresolvekit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjm-rivera%2Fresolvekit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjm-rivera%2Fresolvekit/lists"}