Resolve ISO country codes from profile locations and biographies, fast and offline.
Project description
country_resolver
Fast, offline country resolution for social media profiles.
country_resolver is a Python package for inferring a user's country from social media profile information. It is designed for noisy, real-world profile data from platforms such as X (formerly Twitter), GitHub, Mastodon, Bluesky, and similar services.
The package consists of two complementary modules:
| Module | Purpose |
|---|---|
| Country Resolver | Resolves the dedicated location field into an ISO 3166-1 alpha-2 country code. |
| Bio Resolver | Infers a user's current country of residence from profile biographies using natural language processing. |
Together they provide a fast, explainable solution for country inference without relying on online geocoding services for most lookups.
Why Two Resolvers?
Profile location fields and biographies require different approaches.
A location field is usually short and structured:
Lagos, Nigeria
๐ณ๐ฌ
Naija
Berlin
A biography is free-form natural language:
Originally from Nigeria.
Based in Berlin.
AI Engineer โข Living in Canada ๐จ๐ฆ
Building software.
Born in Ghana.
Trying to process both using the same algorithm either misses valid signals or produces unnecessary false positives.
country_resolver therefore provides two specialized resolvers that can be used independently or together.
Features
- โก Offline-first resolution
- ๐ ISO 3166-1 alpha-2 country codes
- ๐๏ธ City-to-country lookup
- ๐ฉ Flag emoji support
- ๐ค Country aliases and abbreviations
- โ๏ธ Fuzzy matching for misspellings
- ๐ง spaCy-powered biography analysis
- ๐ Confidence scoring and evidence tracking
- ๐ Explainable predictions
- ๐งช Comprehensive unit tests
- ๐ Optional online geocoder fallback for address-like locations
Installation
pip install country-resolver
For Bio Resolver, also install the English spaCy model:
python -m spacy download en_core_web_sm
Quick Start
Country Resolver
from country_resolver.location import CountryResolver
resolver = CountryResolver()
resolver.resolve("Lagos, Nigeria")
'NG'
Bio Resolver
from country_resolver.bio import BioResolver
bio = BioResolver(location)
bio.resolve(
"Originally from Nigeria. Based in Berlin."
)
'DE'
Which Resolver Should I Use?
| Your data | Recommended module |
|---|---|
| Profile location field | Country Resolver |
| Profile biography | Bio Resolver |
| Both | Use both together for the highest accuracy |
Example Inputs
| Input | Module | Output |
|---|---|---|
Nigeria |
Location | NG |
๐ณ๐ฌ |
Location | NG |
Naija |
Location | NG |
Lagos |
Location | NG |
Caneda |
Location | CA |
Kora Nort |
Location | KP |
Earth |
Location | None |
Based in Berlin. |
Bio | DE |
Living in Canada ๐จ๐ฆ |
Bio | CA |
Originally from Nigeria. Living in Germany. |
Bio | DE |
Package Architecture
country_resolver/
โ
โโโ location/
โ โโโ resolver.py
โ โโโ lookup.py
โ โโโ normalize.py
โ โโโ geocoder.py
โ โโโ ...
โ
โโโ bio/
โโโ resolver.py
โโโ parser.py
โโโ scoring.py
โโโ extractors.py
โโโ ...
Design Philosophy
Offline First
The package performs all primary lookups locally.
Network requests are made only when the optional geocoder is enabled for address-like inputs.
Deterministic
The same input always produces the same output.
Conservative
Returning None is preferred over making an incorrect prediction.
Explainable
Both resolvers expose the reasoning behind their predictions, making results suitable for debugging, analytics, and machine learning pipelines.
Modular
Each resolver can be used independently, while sharing the same country resolution infrastructure.
Documentation
Detailed module documentation is available in:
location/README.mdbio/README.md
These documents describe each resolver's internal workflow, API, limitations, examples, and implementation details.
Testing
Run the full test suite with:
pytest
Roadmap
Future development may include:
- Additional language support
- Combined profile resolver
- More profile signal resolvers
License
MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file country_resolver-0.1.1.tar.gz.
File metadata
- Download URL: country_resolver-0.1.1.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee24ca84fd0e2bf2423a4d9aed646a8f5f0877636ed856d06ad3df2863e61832
|
|
| MD5 |
0ff1de2ab5de1fc3b97fb7a6f900595e
|
|
| BLAKE2b-256 |
7d741a592f42dc1953fabcb418f6d3e251d52f2fb04e795895c0dc2532aca4bd
|
Provenance
The following attestation bundles were made for country_resolver-0.1.1.tar.gz:
Publisher:
publish.yml on dinyelum/country-resolver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
country_resolver-0.1.1.tar.gz -
Subject digest:
ee24ca84fd0e2bf2423a4d9aed646a8f5f0877636ed856d06ad3df2863e61832 - Sigstore transparency entry: 2192181468
- Sigstore integration time:
-
Permalink:
dinyelum/country-resolver@5893a9b349865ab1706b7f9a9efc8d2ab7952676 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dinyelum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5893a9b349865ab1706b7f9a9efc8d2ab7952676 -
Trigger Event:
push
-
Statement type:
File details
Details for the file country_resolver-0.1.1-py3-none-any.whl.
File metadata
- Download URL: country_resolver-0.1.1-py3-none-any.whl
- Upload date:
- Size: 28.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a887aa941832be0927231917bfc6812b83ed0051ed5494bc2dcb5562ebed3697
|
|
| MD5 |
aaa9570fb3f2514d11bce4a2caa0840b
|
|
| BLAKE2b-256 |
3b50e7922eddba063abdf73e03725d9d9500686799a742fd5977315ca420fc04
|
Provenance
The following attestation bundles were made for country_resolver-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on dinyelum/country-resolver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
country_resolver-0.1.1-py3-none-any.whl -
Subject digest:
a887aa941832be0927231917bfc6812b83ed0051ed5494bc2dcb5562ebed3697 - Sigstore transparency entry: 2192181479
- Sigstore integration time:
-
Permalink:
dinyelum/country-resolver@5893a9b349865ab1706b7f9a9efc8d2ab7952676 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dinyelum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5893a9b349865ab1706b7f9a9efc8d2ab7952676 -
Trigger Event:
push
-
Statement type: