Skip to main content

Deprecated. bblocks-places is no longer maintained. 0.0.6 is the final release. Please migrate to resolvekit, which covers the same place-resolution functionality and is under active development.

bblocks-places

Resolve and standardize places and work with political and geographic groupings

PyPI PyPI - Python Version Docs Code style: black codecov

Working with country data can be tedious. One source calls it “South Korea” another says “Republic of Korea” a third uses “KOR” — and suddenly your analysis breaks and you spend hours manually standardizing all the names. These inconsistencies are common in cross-geographic datasets and can lead to data cleaning headaches, merge errors, or misleading conclusions.

bblocks-places eliminates this hassle by offering a simple, reliable interface to resolve, standardize, and work with country, region, and other place names.

Key features:

  • Disambiguate and standardize free-text country names (e.g. "Ivory Coast" → “Côte d’Ivoire”)
  • Convert between place formats like ISO codes and official names
  • Filter and retrieve countries by attributes like region, income group, or UN membership
  • Customize resolution logic with your own concordance or override mappings

Built on top of Google's Data Commons, an open knowledge graph integrating public data from the UN, World Bank, and more. bblocks-places is part of the bblocks ecosystem, a set of Python packages designed as building blocks for working with data in the international development and humanitarian sectors.

Read the documentation for more details on how to use the package and the motivation for its creation.

Installation

The package can be installed in various ways.

pip install bblocks-places

Or install the main bblocks package with an extra:

pip install bblocks[places]

Usage

Import the package and start resolving places:

from bblocks import places

Lets start with a very simple example. Say we have a list of countries with non standard names

countries = ["zimbabwe", " Italy ", "USA", "Cote d'ivoire"]

We can easily resolve these names to a standard format such as ISO3 codes

resolved_countries = places.resolve_places(countries, to_type="iso3_code")

print(resolved_countries)
# Output:
# ['ZWE', 'ITA', 'USA', 'CIV']

This works with pandas DataFrames too.

import pandas as pd

df = pd.DataFrame({"country": countries})

# Add the ISO3 codes to the DataFrame
df["iso3_code"] = places.resolve_places(df["country"], to_type="iso3_code")

print(df)
# Output:
#       country         iso3_code
# 0     zimbabwe        ZWE
# 1     Italy           ITA
# 2     USA             USA
# 3     Cote d'ivoire   CIV

Filter places

Let's say that we are only interested in countries in Africa. It is easy to filter our countries with the filter_places function.

african_countries = places.filter_places(countries,
                                         filters={"region": "Africa"})

print(african_countries)
# Output:
# ['zimbabwe', "Cote d'ivoire"]

Get places

We don't always want to resolve or standardize places. Sometimes we simple want to know what places belong to a particular category. For example we might want to know what countries in Africa are classified as upper income

ui_africa = places.get_places(filters={"region": "Africa",
                                       "income_level": ["Upper middle income",
                                                        "High income"]},
                              place_format="name_short"
                              )

print(ui_africa)
# Output:
# ['Algeria', 'Botswana', 'Equatorial Guinea', 'Gabon', 'Libya',
# 'Mauritius', 'Namibia', 'Seychelles', 'South Africa']

Visit the documentation page for the full package documentation and examples.

Contributing

Contributions are welcome! Please see the CONTRIBUTING page for details on how to get started, report bugs, fix issues, and submit enhancements.

Metadata

Release files for bblocks-places 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bblocks-places 0.0.6
File Size Uploaded
bblocks_places-0.0.6.tar.gz 27.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bblocks-places 0.0.6
File Interpreter ABI Platform
bblocks_places-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 55.4 kB

Release files / bblocks_places-0.0.6.tar.gz

Download URL bblocks_places-0.0.6.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d00674951d76e7943570f533e6fce307aec0465ea7fa0e76683ac77455a415a4
BLAKE2b-256 checksum
How to use checksums
834ec02642f5a0e895f5ab102a7e74a2931a5491a0f2e9e89fb76158cb1d921b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / bblocks_places-0.0.6-py3-none-any.whl

Download URL bblocks_places-0.0.6-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1226f97c8e2560156a3037cde8f6c787d3df468fa437f3ec2e65ce6724c9e0c1
BLAKE2b-256 checksum
How to use checksums
df3dc6a35a97ef4a40d10af03b2df0eb03d08f444c6b1421ec2aca9d1f1d9c66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page