Python client and CSV parser for the Sustax User API (SUA)
Project description
sustax-client
A small Python package for the Sustax User API and for parsing the Sustax global climate models by means of CSV files exported by Sustax (see https://sustax.earth). This repository is prepared in a standard src/ layout so it can be:
- developed locally with
pip install -e . - published to the GitLab PyPI registry
- later published to PyPI after a final package-name check
What is included
SustaxClientfor authentication, catalog lookup, pricing, purchases, downloads, status polling, coordinates, and balance checksload_sustax_file()to load Sustax CSV files into pandas DataFrames or nested numpy-friendly dictionaries- tests for the parser and client input validation
- Python and R examples
- GitLab CI config for build and package publishing
Repository layout
sustax-client/
├── .gitignore
├── .gitlab-ci.yml
├── LICENSE
├── README.md
├── pyproject.toml
├── src/
│ └── sustax_client/
│ ├── __init__.py
│ ├── client.py
│ └── parser.py
├── tests/
│ ├── test_client.py
│ └── test_parser.py
└── examples/
├── python/
│ └── quickstart.py
└── r/
└── quickstart.R
Installation
Local development
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .[dev]
From a package registry
Once published:
pip install sustax-client
If you publish first to the GitLab package registry, use that registry URL in pip or .pypirc.
Quick start
1. Authenticate and inspect the catalog
from sustax_client import SustaxClient
with SustaxClient() as client:
client.authenticate("your_username", "your_password")
catalog = client.get_variables_id()
print(catalog)
2. Preview pricing for a point request
from sustax_client import SustaxClient
with SustaxClient() as client:
client.authenticate("your_username", "your_password")
quote = client.view_price_request(
lat=41.3874,
lon=2.1686,
year_from=2020,
year_to=2030,
sustax_code_ids=[12345],
)
print(quote)
3. Buy, download, and unzip a request
from sustax_client import SustaxClient
with SustaxClient() as client:
client.authenticate("your_username", "your_password")
request_info = client.buy_data(
lat=41.3874,
lon=2.1686,
year_from=2020,
year_to=2030,
sustax_code_ids=[12345],
acceptance_sustax_disclaimer=True,
)
zip_path = client.download_file(request_info["url"], dest_dir="downloads")
extracted = client.unzip_download(dest_dir="downloads/unzipped")
print(zip_path)
print(extracted)
4. Load a Sustax CSV with pandas
from sustax_client import load_sustax_file
climate_df, metrics_df, metadata = load_sustax_file(
"downloads/unzipped/example.csv",
return_pandas_df=True,
return_metadata=True,
)
print(climate_df.head())
print(metrics_df.head())
print(metadata)
Supported request modes
The packaged client supports the three location modes described in the Sustax documentation:
- point coordinates:
lat,lon - ROI / bounding box:
lat=[north, south],lon=[west, east] - postal code lookup:
postal_code,country
CSV parser behavior
load_sustax_file() assumes the exported file is a Sustax CSV with three main blocks:
- metadata
- accuracy metrics
- climate payload time series
By default it returns two pandas DataFrames:
- climate payload indexed by time
- metrics indexed by scenario
Set return_pandas_df=False if you prefer nested dictionaries and a numpy datetime array.
Development
Run tests:
pytest
Build distributions:
python -m build
Publish to GitLab package registry
The included .gitlab-ci.yml publishes a package with build and twine when a tag is pushed.
Required CI variables:
TWINE_USERNAMETWINE_PASSWORD
Before publishing to PyPI
Do these checks first:
- Confirm the final package name is available on PyPI.
- Confirm the project license you want to use.
- Replace the placeholder contact metadata in
pyproject.tomlif needed. - Decide whether examples should stay in the main repo or move to docs.
License
MIT
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 sustax_client-0.1.2.tar.gz.
File metadata
- Download URL: sustax_client-0.1.2.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bace78ac8d571da279ad6ea15547b1479f27abdb6f869a473bbb482a13987c4f
|
|
| MD5 |
da8151d5a5cdbd20fba64381a5738f42
|
|
| BLAKE2b-256 |
2e53fd359cdb0653b83140e7361ccf31d1c24a503903c201a59e61bf8a211ad3
|
File details
Details for the file sustax_client-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sustax_client-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
695a8f4a6122f98cb4e01bd58fe1cf536aba7d9aaf21ece41301098db7dd989d
|
|
| MD5 |
6a05720594f6fafefb83e0f8f05df9be
|
|
| BLAKE2b-256 |
0fd5f28cf68249092496600a53917539cc406f74d4c3518fbc876260864d916f
|