Skip to main content

Python client for Singapore government open data (data.gov.sg, LTA, OneMap)

Project description

Disclaimer: This is not an official Singapore Government project. It is an independent open-source library and is not affiliated with, endorsed by, or operated by any government agency.

publicsgdata

License: MIT

Python client for Singapore government open data: data.gov.sg today, LTA and OneMap later.

Install

Requires uv.

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)

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)

Development

You'll need uv.

./scripts/dev_setup.sh         # creates .venv from uv.lock
./scripts/format.sh
./scripts/validate.sh
./scripts/test.sh              # unit tests, runs in CI
./scripts/test_integration.sh  # hits the real API, local only

Or run things directly: uv run pytest, uv run ruff check ., etc.

See CONTRIBUTING.md if you're opening a PR.

Roadmap

  • v0.1.0: DataGovSGClient
  • v0.2.0: LTAClient (LTA DataMall)
  • v0.3.0: OneMapClient

License

MIT. See LICENSE.

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

publicsgdata-0.1.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

publicsgdata-0.1.2-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file publicsgdata-0.1.2.tar.gz.

File metadata

  • Download URL: publicsgdata-0.1.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for publicsgdata-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c94e5e9474c66314ab0bb1c285cbf604ebb7517920f94ff3d4a58f952021b361
MD5 6602c9e5272670ad29dd0157275e0705
BLAKE2b-256 592c97fdc04e73913f69d59e65f76e3db1a1a72839ce808e1833cb4465658c1c

See more details on using hashes here.

File details

Details for the file publicsgdata-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: publicsgdata-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for publicsgdata-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 726250e09f2cdd5b3cf76c260fb1b05988ecb0ebf2fdb622a120b0f6fab13d94
MD5 53af0cdd1c84e8fdf46805b4c5a91cbf
BLAKE2b-256 c6ae28a718c2b13aa3f496c9755aaa6174a7a027949f91d2a40339a6727c6c9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page