Skip to main content

A Python client for accessing sub-national variation data through the Space2Stats API

Project description

Space2Stats Python Client

A Python client for accessing the Space2Stats API, providing easy access to consistent, comparable, and authoritative sub-national variation data from the World Bank.

API Methods

get_topics()

Returns a DataFrame containing available dataset themes/topics from the STAC catalog.


get_fields()

Returns a list of all available fields that can be used with the API.


get_properties(item_id: str)

Returns a DataFrame with descriptions of variables for a specific dataset.


fetch_admin_boundaries(iso3: str, adm: str)

Fetches administrative boundaries from GeoBoundaries API for a given country and admin level.


get_summary(gdf, spatial_join_method, fields, geometry=None)

Extracts H3 level data for areas of interest.

  • Parameters:
    • gdf: GeoDataFrame containing areas of interest
    • spatial_join_method: "touches", "centroid", or "within"
    • fields: List of field names to retrieve
    • geometry: Optional "polygon" or "point" to include H3 geometries

get_aggregate(gdf, spatial_join_method, fields, aggregation_type)

Extracts summary statistics from H3 data.

  • Parameters:
    • gdf: GeoDataFrame containing areas of interest
    • spatial_join_method: "touches", "centroid", or "within"
    • fields: List of field names to retrieve
    • aggregation_type: "sum", "avg", "count", "max", or "min"

get_summary_by_hexids(hex_ids, fields, geometry)

Retrieves statistics for specific H3 hexagon IDs.

  • Parameters:
    • hex_ids: List of H3 hexagon IDs to query
    • fields: List of field names to retrieve
    • geometry: Optional; specifies if H3 geometries should be included ("polygon" or "point")

get_aggregate_by_hexids(hex_ids, fields, aggregation_type)

Aggregates statistics for specific H3 hexagon IDs.

  • Parameters:
    • hex_ids: List of H3 hexagon IDs to aggregate
    • fields: List of field names to aggregate
    • aggregation_type: Type of aggregation ("sum", "avg", "count", "max", "min")

Quick Start

pip install space2stats-client
from space2stats_client import Space2StatsClient
import geopandas as gpd

# Initialize the client
client = Space2StatsClient()

# Get available topics/datasets
topics = client.get_topics()
print(topics)

# Get fields for a specific dataset
fields = client.get_fields("dataset_id")
print(fields)

# Get data for an area of interest
gdf = gpd.read_file("path/to/your/area.geojson")
summary = client.get_summary(
    gdf=gdf,
    spatial_join_method="centroid",
    fields=["population", "gdp"]
)

# Get aggregated statistics
aggregates = client.get_aggregate(
    gdf=gdf,
    spatial_join_method="centroid",
    fields=["population", "gdp"],
    aggregation_type="sum"
)

Documentation

For full documentation, visit Space2Stats Documentation.

License

This project is licensed under the World Bank Master Community License Agreement. See the LICENSE file for details.

Disclaimer

The World Bank makes no warranties regarding the accuracy, reliability, or completeness of the results and content. The World Bank disclaims any liability arising from the use of this software.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

space2stats_client-1.1.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

space2stats_client-1.1.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file space2stats_client-1.1.1.tar.gz.

File metadata

  • Download URL: space2stats_client-1.1.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for space2stats_client-1.1.1.tar.gz
Algorithm Hash digest
SHA256 bfc5fa4de5fe0ff8a8d3e30eae9755a2825c00dde90a8aeb57f4708da8c7fa58
MD5 f033bba0ee676105b9adb17f5d83b39d
BLAKE2b-256 fbf7953aa071816c08a7b4898d4614491df11b74a3fff5d9a2464944a12d3dbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for space2stats_client-1.1.1.tar.gz:

Publisher: client-release.yml on worldbank/DECAT_Space2Stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file space2stats_client-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for space2stats_client-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f30fda828adeabc9bde46c90bbf220761db2d24cfc126f3263c2d0acf4cd083
MD5 146c03f71ee1ebd482575b6b06b4b2da
BLAKE2b-256 dbb67daf588c1226f79d81868089396810690748f8ab7864e9f6ed27ba3afaba

See more details on using hashes here.

Provenance

The following attestation bundles were made for space2stats_client-1.1.1-py3-none-any.whl:

Publisher: client-release.yml on worldbank/DECAT_Space2Stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page