dataio.sdk.admin¶
Admin SDK for DataIO - Dataset upload and management operations.
Module Contents¶
Classes¶
Admin API Client for uploading datasets to DataIO. |
Functions¶
Returns (region_id, None), or (None, why it can’t be mapped). |
|
A positive whole-number LGD code (int, integral float or digit string), else None. A fractional code like 527.9 must not round down onto another region’s id. |
|
The API’s error detail, or the start of the body when it isn’t a JSON object. |
|
raise_for_status, with the API’s error detail in the message. |
Data¶
API¶
- dataio.sdk.admin.console¶
‘Console(…)’
- class dataio.sdk.admin.DataIOAdminAPI(base_url: Optional[str] = None, api_key: Optional[str] = None, data_dir: Optional[str] = None)[source]¶
Admin API Client for uploading datasets to DataIO.
- Parameters:
base_url – The base URL of the DataIO API. Defaults to DATAIO_API_BASE_URL env var.
api_key – The API key for admin access. Defaults to DATAIO_API_KEY env var.
data_dir – The directory containing datasets. Defaults to DATAIO_DATA_DIR env var.
Initialization
- _parse_dataset_folder(folder_path: str) Dict[str, Any][source]¶
Parse a dataset folder and extract all required information.
Expected folder structure:
{ds_id}-{title}/
info.yml (dataset-level metadata)
metadata.yaml (table-level metadata)
*.csv (data files)
- create_data_owner(name: str, contact_person: Optional[str] = None, contact_person_email: Optional[str] = None) Dict[source]¶
Create a data owner entry.
- Parameters:
name – Name of the data owner (must be unique)
contact_person – Optional contact person name
contact_person_email – Optional contact person email
- Returns:
Created data owner object
- ensure_data_owner_exists(name: str) bool[source]¶
Ensure a data owner exists, creating it if necessary.
- Parameters:
name – Name of the data owner
- Returns:
True if created, False if already existed
- create_raw_dataset(rds_id: str, title: str, source: str) Dict[source]¶
Create a raw dataset entry.
- Parameters:
rds_id – Raw dataset identifier
title – Raw dataset title
source – Raw dataset source (URL or description)
- Returns:
Created raw dataset object
- create_dataset(ds_id: str, title: str, collection_id: str, data_owner_name: str, raw_dataset_ids: List[str], description: Optional[str] = None, spatial_coverage_region_id: Optional[str] = None, spatial_resolution: Optional[str] = None, temporal_coverage_start_date: Optional[str] = None, temporal_coverage_end_date: Optional[str] = None, temporal_resolution: Optional[str] = None, access_level: str = 'NONE', tags: Optional[List[str]] = None, additional_metadata: Optional[Dict] = None) Dict[source]¶
Create a dataset.
- Parameters:
ds_id – Dataset identifier (12 chars, must start with collection_id)
title – Dataset title
collection_id – Collection identifier (first 6 chars of ds_id)
data_owner_name – Name of data owner (must exist in database)
raw_dataset_ids – List of raw dataset IDs to link
description – Optional description
spatial_coverage_region_id – Optional region ID
spatial_resolution – Optional spatial resolution enum
temporal_coverage_start_date – Optional start date (YYYY or YYYY-MM-DD)
temporal_coverage_end_date – Optional end date
temporal_resolution – Optional temporal resolution enum
access_level – Access level (NONE|VIEW|DOWNLOAD)
tags – Optional list of tags
additional_metadata – Optional additional metadata dict
- Returns:
Created dataset object
- upload_table(dataset_id: str, bucket_type: str, csv_path: pathlib.Path, table_metadata: Dict) Dict[source]¶
Upload a table (CSV file) to a dataset.
- Parameters:
dataset_id – Dataset ID to upload to
bucket_type – Bucket type (PREPROCESSED or STANDARDISED)
csv_path – Path to the CSV file
table_metadata – Table metadata dict with table_name, description, data_dictionary
- Returns:
Upload response
- upload_dataset_folder(folder_path: str, bucket_type: str = 'STANDARDISED', dry_run: bool = False) Dict[str, Any][source]¶
Upload an entire dataset folder (create dataset + upload all tables).
- Parameters:
folder_path – Path to the dataset folder
bucket_type – Bucket type (PREPROCESSED or STANDARDISED)
dry_run – If True, only validate without making API calls
- Returns:
Summary of upload operation
- upload_all_datasets(data_dir: Optional[str] = None, bucket_type: str = 'STANDARDISED', dry_run: bool = False) List[Dict[str, Any]][source]¶
Upload all dataset folders in the data directory.
- Parameters:
data_dir – Directory containing dataset folders
bucket_type – Bucket type for all uploads
dry_run – If True, only validate without making API calls
- Returns:
List of upload results for each dataset
- create_shapefile_version(version: str, source: str, dataset_id: Optional[str] = None, description: Optional[str] = None, released_at: Optional[str] = None) Dict[source]¶
Create a shapefile version (one upload batch, e.g. “kgis-2026-08”).
- Parameters:
version – Version name: lowercase letters, digits, “.” or “-”
source – Where the boundaries come from
dataset_id – Catalogue ds_id the boundaries are published as
description – Free-text notes
released_at – ISO timestamp that orders versions (default: now). Downloads without a version get the newest version.
- Returns:
The created version
- upload_shapefile(region_id: str, geojson_path: str, version: str, overwrite: bool = False) Dict[source]¶
Upload one region’s boundary GeoJSON (Feature or FeatureCollection).
The server checks the region exists and the GeoJSON is a lon/lat Polygon/MultiPolygon, and stores it in the ARTPARK GeoJSON spec format: a FeatureCollection whose features have id = region_id and properties starting with regionName/regionType/parentID/parentName. A missing lastUpdated is filled in from the version’s release date.
- Parameters:
region_id – Region id, e.g. “subdistrict_5433”
geojson_path – Path to the .geojson file
version – Shapefile version to upload into (create it first)
overwrite – Replace the region’s file if the version already has one
- Returns:
Upload response
- _post_shapefile(session, region_id: str, path: pathlib.Path, version: str, overwrite: bool) Dict[source]¶
- upload_shapefile_folder(folder_path: str, version: str, overwrite: bool = False, dry_run: bool = False, workers: int = 4, id_map: Optional[Dict[str, str]] = None) List[Dict[str, Any]][source]¶
Upload every *.geojson under a folder, one region per file.
Each file’s region id is “
_ ”, read from the feature’s properties (the standardised boundary schema), so file names don’t matter. Files without regionType/lgdCode, with more than one feature, or mapping to the same region id as another file are skipped. Regions the version already has are skipped unless overwrite is set, so an interrupted upload can simply be re-run. - Parameters:
folder_path – Folder to scan recursively
version – Shapefile version to upload into (create it first)
overwrite – Replace files the version already has
dry_run – Only map files to region ids; upload nothing
workers – Parallel uploads
id_map – For levels whose region ids aren’t “
” (e.g. wards: ward - ), maps that derived id to the region id. Files whose derived id isn’t in the map are skipped.
- Returns:
One result per file: file, region_id, status (uploaded / exists / skipped / failed / planned) and detail
- dataio.sdk.admin._region_id_from_geojson_file(path: pathlib.Path)[source]¶
Returns (region_id, None), or (None, why it can’t be mapped).
- dataio.sdk.admin._integral_lgd_code(value) Optional[int][source]¶
A positive whole-number LGD code (int, integral float or digit string), else None. A fractional code like 527.9 must not round down onto another region’s id.