publicsgdata
Python client for Singapore government open data: data.gov.sg today, LTA and OneMap later.
Install
uv pip install publicsgdata
Quickstart
from publicsgdata import DataGovSGClient
with DataGovSGClient() as client: # optional: api_key="..." or DATA_GOV_SG_API_KEY
catalog = client.collections.list()
print(f"{len(catalog.collections)} collections")
print(catalog.collections[0].name)
# HDB resale prices (swap in any dataset ID)
rows = client.datasets.list_rows("d_8b84c4ee58e3cfc0ece0d773c8ca6abc", limit=10)
for row in rows.rows:
print(row.model_dump())
pm25 = client.realtime.pm25.get()
print(pm25.items[0].readings)
Download full dataset
from publicsgdata import DataGovSGClient
with DataGovSGClient() as client:
path = client.datasets.download_file(
"d_8b84c4ee58e3cfc0ece0d773c8ca6abc",
"hdb-resale.csv",
)
print(path)
Async
from publicsgdata import AsyncDataGovSGClient
async with AsyncDataGovSGClient() as client:
rows = await client.datasets.list_rows("d_8b84c4ee58e3cfc0ece0d773c8ca6abc", limit=5)
print(len(rows.rows))
Custom HTTP client
Pass your own httpx client if you need custom timeouts, proxies, etc.
import httpx
from publicsgdata import DataGovSGClient
with httpx.Client(timeout=30.0) as http:
client = DataGovSGClient(http_client=http)
print(len(client.collections.list().collections))
Authentication
You can call the API without a key while experimenting. For regular use, get a key from data.gov.sg and set:
export DATA_GOV_SG_API_KEY="your-key"
Environment variables
| Variable | Required | Description |
|---|---|---|
DATA_GOV_SG_API_KEY |
No | data.gov.sg API key (x-api-key header) |
Roadmap
- v0.1.0:
DataGovSGClient - v0.2.0:
LTAClient(LTA DataMall) - v0.3.0:
OneMapClient
Metadata
Release files for publicsgdata 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| publicsgdata-0.2.2.tar.gz | 12.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| publicsgdata-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.8 kB
Release files / publicsgdata-0.2.2.tar.gz
| Download URL | publicsgdata-0.2.2.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c9a3d2b93d2271dbaf5a2b3ad5018fa13b09c412a6cb497a3f13153ca57ade3
|
|
BLAKE2b-256 checksum How to use checksums |
996508ba5d31ac12cab6842072f4ba06c98343921545a52da763af6a7f33b747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / publicsgdata-0.2.2-py3-none-any.whl
| Download URL | publicsgdata-0.2.2-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab92150c7e5d88ab9f4db3544a806e7eb236090fbb5bd5630b91b636efecd0ef
|
|
BLAKE2b-256 checksum How to use checksums |
a968128ddb1faa865becf2176aa5c30fd0cbd4a9ccd09fa412d5ab7b0235e0e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|