Skip to content

Unofficial Python package for interacting with APIs available at Land Transport Authority's DataMall.

License

Notifications You must be signed in to change notification settings

yuhui/landtransportsg

Repository files navigation

landtransportsg

Python 3.10 PyPi PyPi status CodeCov coverage downloads GNU General Public License v3.0 Documentation Status

This is an unofficial Python package for interacting with APIs available at LTA DataMall.

Installing the package

Install the package using pip:

pip install landtransportsg

Using the package

Pre-requisite:

The main steps are:

  1. Import a client class.
  2. Instantiate an object from the client class.
  3. Call a function on that object.

For more information, refer to the documentation.

Usage overview

Interacting with LTA DataMall's API is done through one of four clients, where each client corresponds with a set of endpoints.

The four clients are:

  • ActiveMobility
  • Geospatial
  • PublicTransport
  • Traffic

Each client contains several public functions, one function per endpoint. A function's name is the same as its corresponding endpoint's ending path.

Some functions accept named arguments, where an argument corresponds with a parameter that the endpoint accepts.

Why have separate clients instead of one single client?

Without knowing how LTA DataMall's API will evolve, and noticing that the endpoints were themselves already partitioned into sets, it seemed like a good idea to keep each set of endpoints in its own contextual client. This allows for each set of endpoints to be customised on their own, e.g. the PublicTransport passenger volume-related endpoints allow for a string to be returned, whereas the other endpoints return a list.

Reference

LTA DataMall's Developer Guide

Other Packages Built by Me

If you like this package, you may be interested in these packages that I have built to work with other Government of Singapore APIs:

  • datagovsg: for interacting with APIs available at Data.gov.sg.
  • singstat: for interacting with APIs available at SingStat.gov.sg.