Python client for Singapore government open data (data.gov.sg, LTA, OneMap)
Project description
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
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 publicsgdata-0.2.0.tar.gz.
File metadata
- Download URL: publicsgdata-0.2.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c3cb559615d775cde53587a135e9f9c902af33c002199e375d01505eca2a6eb
|
|
| MD5 |
ac83d4fcfa31ae89568b52c6139bd252
|
|
| BLAKE2b-256 |
75cd4fe989ecfc4c6c4b905315ecd82505276dc2d7b87c4cb4728658e0414b18
|
File details
Details for the file publicsgdata-0.2.0-py3-none-any.whl.
File metadata
- Download URL: publicsgdata-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f1c165a9706c44f4a8ee7116dba065b65e4a90315391932f85218bf37579ae0
|
|
| MD5 |
062f92645e5c5a8480093b380de8665b
|
|
| BLAKE2b-256 |
5cf86942c82d91a6fe0420d0a940c1e3c0bdf7c654b772fc1d249254b88d8294
|