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 interestspatial_join_method: "touches", "centroid", or "within"fields: List of field names to retrievegeometry: 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 interestspatial_join_method: "touches", "centroid", or "within"fields: List of field names to retrieveaggregation_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 queryfields: List of field names to retrievegeometry: 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 aggregatefields: List of field names to aggregateaggregation_type: Type of aggregation ("sum", "avg", "count", "max", "min")
get_timeseries_fields()
Returns a list of available fields from the timeseries table.
get_timeseries(gdf, spatial_join_method, start_date=None, end_date=None, fields=None)
Gets timeseries data for areas of interest.
- Parameters:
gdf: GeoDataFrame containing areas of interestspatial_join_method: "touches", "centroid", or "within"start_date: Optional start date (format: 'YYYY-MM-DD')end_date: Optional end date (format: 'YYYY-MM-DD')fields: Optional list of field names to retrieve
get_timeseries_by_hexids(hex_ids, start_date=None, end_date=None, fields=None)
Gets timeseries data for specific H3 hexagon IDs.
- Parameters:
hex_ids: List of H3 hexagon IDs to querystart_date: Optional start date (format: 'YYYY-MM-DD')end_date: Optional end date (format: 'YYYY-MM-DD')fields: Optional list of field names to retrieve
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
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 space2stats_client-1.2.0.tar.gz.
File metadata
- Download URL: space2stats_client-1.2.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7b4e36ae34030f436451b5e0df43cdabb6771bb52253c7cf85ce7e0a6670fe6
|
|
| MD5 |
5edfec08fede8b95ac0bb407c344a546
|
|
| BLAKE2b-256 |
a5756a9763362bbcef967f3e10384c0d3299eb19ed11ff481d4957be94177c7c
|
Provenance
The following attestation bundles were made for space2stats_client-1.2.0.tar.gz:
Publisher:
client-release.yml on worldbank/DECAT_Space2Stats
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
space2stats_client-1.2.0.tar.gz -
Subject digest:
e7b4e36ae34030f436451b5e0df43cdabb6771bb52253c7cf85ce7e0a6670fe6 - Sigstore transparency entry: 201477847
- Sigstore integration time:
-
Permalink:
worldbank/DECAT_Space2Stats@77950999c93e4fb5204184e42977b4ded5cb24f9 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/worldbank
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
client-release.yml@77950999c93e4fb5204184e42977b4ded5cb24f9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file space2stats_client-1.2.0-py3-none-any.whl.
File metadata
- Download URL: space2stats_client-1.2.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4fa6282d4dc1c1982750d5560ab5671524e899fe16ef4f8a2e178ac06856dce
|
|
| MD5 |
c5b87916e27d70076c70fd1e4e0577c7
|
|
| BLAKE2b-256 |
7d92e9494f21a9c08b38f174ae213428fe291e1688aace7891bfb6d40787a245
|
Provenance
The following attestation bundles were made for space2stats_client-1.2.0-py3-none-any.whl:
Publisher:
client-release.yml on worldbank/DECAT_Space2Stats
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
space2stats_client-1.2.0-py3-none-any.whl -
Subject digest:
e4fa6282d4dc1c1982750d5560ab5671524e899fe16ef4f8a2e178ac06856dce - Sigstore transparency entry: 201477853
- Sigstore integration time:
-
Permalink:
worldbank/DECAT_Space2Stats@77950999c93e4fb5204184e42977b4ded5cb24f9 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/worldbank
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
client-release.yml@77950999c93e4fb5204184e42977b4ded5cb24f9 -
Trigger Event:
release
-
Statement type: