{"id":22963643,"url":"https://github.com/half0wl/datagovsg_api","last_synced_at":"2025-08-13T07:34:48.861Z","repository":{"id":62566591,"uuid":"87529763","full_name":"half0wl/datagovsg_api","owner":"half0wl","description":"Unofficial Python API wrapper for public APIs at developers.data.gov.sg","archived":false,"fork":false,"pushed_at":"2023-05-22T21:34:25.000Z","size":18,"stargazers_count":8,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-13T18:36:51.273Z","etag":null,"topics":["api-wrapper","data","government-data","python","singapore"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/half0wl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-04-07T09:33:48.000Z","updated_at":"2024-08-23T08:09:12.000Z","dependencies_parsed_at":"2024-01-30T15:29:51.487Z","dependency_job_id":"dc6cac47-7c90-4bf9-ac0a-825d67576d44","html_url":"https://github.com/half0wl/datagovsg_api","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":0.08333333333333337,"last_synced_commit":"688b352b7f8508861760e87c151bb3cd68eb2f9e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fdatagovsg_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fdatagovsg_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fdatagovsg_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fdatagovsg_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/half0wl","download_url":"https://codeload.github.com/half0wl/datagovsg_api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229614605,"owners_count":18099068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-wrapper","data","government-data","python","singapore"],"created_at":"2024-12-14T19:37:06.362Z","updated_at":"2024-12-14T19:37:07.158Z","avatar_url":"https://github.com/half0wl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datagovsg_api\n\n[![Build Status](https://travis-ci.org/half0wl/datagovsg_api.svg?branch=master)](https://travis-ci.org/half0wl/datagovsg_api) [![Documentation Status](https://readthedocs.org/projects/datagovsg-api/badge/?version=latest)](http://datagovsg-api.readthedocs.io/en/latest/?badge=latest)\n\nUnofficial Python API wrapper for public APIs at [developers.data.gov.sg](https://developers.data.gov.sg/). An API key is required and can be obtained from [https://developers.data.gov.sg/](https://developers.data.gov.sg/).\n\n**Disclaimer**: The author is not associated with data.gov.sg, and this project does not represent data.gov.sg or it's affiliates in any way.\n\n## Installation\n\n`$ pip install datagovsg_api`\n\n## Usage\n\n**API Reference**: https://datagovsg_api.readthedocs.io/en/latest/\n\nThe `TransportAPI` class provides an interface to APIs under the Transport category.\n\n```python\nimport datagovsg_api\n\nsg_transport = datagovsg_api.TransportAPI('API_KEY')\n\n# Get taxi availability\nprint(sg_transport.taxi_availability().json())\n```\n\nThe `EnvironmentAPI` class provides an interface to APIs under the Environment category.\n\n```python\nimport datagovsg_api\n\nsg_environment = datagovsg_api.EnvironmentAPI('API_KEY')\n\n# Get 2-hour weather forecast\nprint(sg_environment.weather_forecast('2-hour').json())\n\n# Get the PSI readings at a particular moment in time\ndatetime_to_retrieve = '2016-12-12T09:45:00'\nprint(sg_environment.psi(date_time=datetime_to_retrieve).json())\n\n# Get the wind direction on a particular date\ndate_to_retrieve = '2016-12-12'\nprint(sg_environment.wind_direction(date=date_to_retrieve).json())\n```\n\nIf you need access to both Transport and Environment APIs, there's an `AllAPI` class.\n\n```python\nimport datagovsg_api\n\nsg_data = datagovsg_api.AllAPI('API_KEY')\n\n# Get taxi availability\nprint(sg_data.taxi_availability().json())\n\n# Get 2-hour weather forecast\nprint(sg_data.weather_forecast(duration='2-hour').json())\n```\n\nAll methods return a `Response` object. Call `.json()` to retrieve the\ndata.\n\n```python\n\u003e\u003e\u003e import datagovsg_api\n\u003e\u003e\u003e sg_transport = datagovsg_api.TransportAPI('API_KEY')\n\u003e\u003e\u003e taxi_availability = sg_transport.taxi_availability()\n\u003e\u003e\u003e type(taxi_availability)\n\u003cclass 'requests.models.Response'\u003e\n\u003e\u003e\u003e taxi_availability.status_code\n200\n\u003e\u003e\u003e taxi_availability.json()\n{'type': 'FeatureCollection', 'crs': {'type': 'link', 'properties': {'href': 'http://spatialreference.org/ref/epsg/4326/ogcwkt/', 'type': 'ogcwkt'}}, 'features': [{'type': 'Feature', 'geometry': {'type': 'MultiPoint', 'coordinates': [[103.61401, 1.25224], [103.6218, 1.274137], [103.62295, 1.28297], [103.6232, 1.29934], [103.62367, 1.30091], [103.62471, 1.30781], [103.62622, 1.28103], [103.6265, 1.29537], [103.62748, 1.28803], [103.62778, 1.28701], [103.62859, 1.31048], [103.62898, 1.31463], [103.62996, 1.28483], [103.63304, 1.31035], [103.63497, 1.32925], [103.63846, 1.33281], [103.64054, 1.32225], [103.64115, 1.31938], [103.64326, 1.33401], [103.64734, 1.31784], [103.64799, 1.32955], ... [truncated]\n```\n\nMost methods have an optional `date` and/or `date_time` parameter which\ncan be used to retrieve the latest available data at that particular moment.\nThe format for `date` is `YYYY-MM-DD` (e.g. `2016-12-12`). The format\nfor `date_time` is `YYYY-MM-DD[T]HH:mm:ss (SGT)` (e.g. `2016-12-12T09:45:00`).\n\n```python\n\u003e\u003e\u003e import datagovsg_api\n\u003e\u003e\u003e sg_environment = datagovsg_api.EnvironmentAPI('API_KEY')\n\u003e\u003e\u003e sg_environment.psi(date='2016-12-12').json()\n{'region_metadata': [{'name': 'national', 'label_location': {'longitude': 0, 'latitude': 0}}, {'name': 'south', 'label_location': {'longitude': 103.82, 'latitude': 1.29587}}, {'name': 'north', 'label_location': {'longitude': 103.82, 'latitude': 1.41803}}, {'name': 'east', 'label_location': {'longitude': 103.94, 'latitude': 1.35735}}, {'name': 'central', 'label_location': {'longitude': 103.82, 'latitude': 1.35735}}, {'name': 'west', 'label_location': {'longitude': 103.7, 'latitude': 1.35735}}], 'items': [{'timestamp': '2016-12-12T01:00:00+08:00', ... [truncated]\n\u003e\u003e\u003e sg_environment.psi(date_time='2016-12-12T09:45:00').json()\n{'region_metadata': [{'name': 'national', 'label_location': {'longitude': 0, 'latitude': 0}}, {'name': 'south', 'label_location': {'longitude': 103.82, 'latitude': 1.29587}}, {'name': 'north', 'label_location': {'longitude': 103.82, 'latitude': 1.41803}}, {'name': 'east', 'label_location': {'longitude': 103.94, 'latitude': 1.35735}}, {'name': 'central', 'label_location': {'longitude': 103.82, 'latitude': 1.35735}}, {'name': 'west', 'label_location': {'longitude': 103.7, 'latitude': 1.35735}}], 'items': [{'timestamp': '2016-12-12T09:00:00+08:00', ... [truncated]\n```\n\n## List of available methods\n\nClick on the hyperlink icon 🔗 for the method's API reference on [readthedocs](https://datagovsg-api.readthedocs.io/en/latest/).\n\n**TransportAPI** [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.TransportAPI)\n\n* `taxi_availability()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.TransportAPI.taxi_availability)\n* `traffic_images()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.TransportAPI.traffic_images)\n\n**EnvironmentAPI**  [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI)\n\n* `weather_forecast()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.weather_forecast)\n* `air_temperature()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.air_temperature)\n* `pm25()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.pm25)\n* `psi()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.psi)\n* `rainfall()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.rainfall)\n* `relative_humidity()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.relative_humidity)\n* `uv_index()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.uv_index)\n* `wind_direction()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.wind_direction)\n* `wind_speed()` [🔗](https://datagovsg-api.readthedocs.io/en/latest/#datagovsg_api.EnvironmentAPI.wind_speed)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalf0wl%2Fdatagovsg_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalf0wl%2Fdatagovsg_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalf0wl%2Fdatagovsg_api/lists"}