API wrappers for interacting with real-time public transport data in Victoria, Australia
Project description
Victorian public transport information API wrappers for Python (pre-release)
Python utilities for interacting with real-time information for public transport in Victoria, Australia, via the Public Transport Victoria (PTV) Timetable API, Yarra Trams' TramTracker data service and the V/Line website.
Package version: 0.5.0
Last updated: 1 June 2026
Tested on Python version: 3.14.5
This repository is hosted on GitLab and mirrored on GitHub. If you are viewing on GitHub, please send any issues, comments and feedback there.
Documentation
The full public API documentation can be found at: https://pizza1016.gitlab.io/ptv-timetable
Overview
This package of modules aims to simplify the process of retrieving and manipulating real-time data for public transport in Victoria, Australia and document each operation and response supported by the APIs.
The package implements interfaces for three data sources:
- PTV Timetable API - the main service for real-time and scheduled public transport information across Victoria;
- Yarra Trams TramTracker - live passenger information for the Melbourne tram network, including planned diversions which the Timetable API lacks; and
- V/Line website - since November 2024, real-time V/Line departures and arrivals information at Southern Cross station for the next 30 minutes, including platform information and estimated time of departure/arrival.
The package minimises the use of third-party modules to improve portability, especially on systems with restrictions.
What's different from accessing the Timetable API directly?
- Simplifying output "types": instead of having a different response schema for each API operation, any object that represents the same concept are consolidated into the same response type (e.g. all responses that represent a public transport stop are instances of the same class:
Stop, instead of the ten or so different representations in the API). Any attribute/field for which the API does not provide a response for will have a sentinel value. - Best-effort documentation: all operations and fields have, as far as practicable, been documented in type hints and docstrings (although some of these are guesses).
- Date and time representation: date inputs and outputs are converted from and to
datetimeobjects with the local time zone of Victoria, so that you do not have to deal with the different string representations of dates and speaking to the API in the UTC time zone as implemented by the Timetable API. - Other quality of life modifications: such as consistent attribute names, fixing typos and removing trailing whitespaces.
Pre-release package
This package is in pre-release. Breaking changes may be made without notice during development.
Direct dependencies
Note that these dependencies may have their own dependencies.
| Package name | Tested on version | Notes |
|---|---|---|
| aiohttp | ≥ 3.13.5 | |
| aiolimiter | ≥ 1.2.1 | |
| ratelimit | ≥ 2.2.1 | |
| requests | ≥ 2.34.2 | |
| tzdata | ≥ 2026.2 | Only required on OSes without a native tz database, including Windows. |
Installation
The recommended method to install this package is via the Python Package Index (PyPI):
python -m pip install ptv-timetable
You can also install from the GitLab Package Registry (authentication not required):
python -m pip install --index-url https://gitlab.com/api/v4/projects/54559866/packages/pypi/simple ptv-timetable
These commands will also install any required dependencies from PyPI.
Usage
This package adds three modules into the root namespace of your interpreter (so they can be directly imported into your code with import <module_name>):
ptv_timetablefor interacting with the PTV Timetable API;ptv_timetable.asyncapiis the asynchronous I/O versionptv_timetable.typesdefines dataclasses used to represent returned API objects;
tramtrackerfor interacting with the TramTracker data service;tramtracker.asyncapiis the asynchronous I/O versiontramtracker.typesdefines dataclasses used to represent returned API objects; and
vlinefor retrieving V/Line Southern Cross departure and arrival information.
Each module defines data types that encapsulate the responses from the APIs to allow access by attribute reference (.) to take advantage of autocompletion systems in IDEs where available. This format also allows each field to be documented, which is not a feature that is available in the raw dicts returned by the APIs.
PTV Timetable API
To use the Timetable API service, you will first need to obtain credentials from PTV:
- Send an email to APIKeyRequest@ptv.vic.gov.au with the subject line
PTV Timetable API - request for key. - You will receive a user ID and a UUID-format signing key in response. This may take several days depending on volume of requests; you will not receive confirmation that your request was received, so hang tight!
(Details: http://ptv.vic.gov.au/ptv-timetable-api/)
Import the ptv_timetable module:
from ptv_timetable import *
This adds the TimetableAPI class and a number of constants for use in method arguments.
Create a new instance of TimetableAPI and provide your user ID and signing key:
timetable = TimetableAPI(dev_id, key)
You can now communicate with the API using the instance methods.
There is also an asyncio version, which you can set up as follows:
import asyncio
from aiohttp.client import ClientSession
from ptv_timetable.asyncapi import *
async def main() -> None:
async with ClientSession() as session:
timetable = AsyncTimetableAPI(dev_id, key, session)
# Your code here
# e.g. routes = await timetable.list_routes(METROPOLITAN_TRAIN)
return
if __name__ == "__main__":
asyncio.run(main())
TramTracker data service
Import the tramtracker module and instantiate TramTrackerAPI:
from tramtracker import *
tracker = TramTrackerAPI()
# Your code here
Or, for asynchronous use:
import asyncio
from aiohttp.client import ClientSession
from tramtracker.asyncapi import *
async def main() -> None:
async with ClientSession() as session:
tracker = AsyncTramTrackerAPI(session)
# Your code here
return
if __name__ == "__main__":
asyncio.run(main())
Southern Cross station V/Line departures and arrivals
Import the vline module and call next_services():
import vline
departures, arrivals, as_at = vline.next_services()
Logging
Some actions are logged under the logger names corresponding to their module names prefixed by "ptv-timetable." (e.g. ptv-timetable.ptv_timetable, ptv-timetable.ptv_timetable.types, ptv-timetable.tramtracker.asyncapi). Use logging.getLogger() to obtain the loggers and you can register your own handlers to retrieve their contents.
Issues and error reporting
To report problems with the package or otherwise give feedback, go to the Issues tab of the repository.
Copyright and licensing
This project's source code is licensed under the Apache Licence 2.0; however, data obtained from the APIs themselves via these modules are licensed separately: PTV Timetable API data are under a Creative Commons Attribution 4.0 International licence, and TramTracker and V/Line data is proprietary. See LICENCE.md for further information.
Project details
Release history Release notifications | RSS feed
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 ptv_timetable-0.5.0.tar.gz.
File metadata
- Download URL: ptv_timetable-0.5.0.tar.gz
- Upload date:
- Size: 60.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f1e8683e5200943143f7edfe4a389cd1e33223e43003a58ad12855e5dd070a4
|
|
| MD5 |
715ca7e164d22e6d5d4e8abd1db6a72f
|
|
| BLAKE2b-256 |
802d097e7092373e7f4bcad3917f7fe0613331c6d5676896c761065e1578a1fe
|
File details
Details for the file ptv_timetable-0.5.0-py3-none-any.whl.
File metadata
- Download URL: ptv_timetable-0.5.0-py3-none-any.whl
- Upload date:
- Size: 64.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45424d9569f6ff6de9fc7ec6b90fb1420285e91a103c7e21dc06fa9ff7708bc9
|
|
| MD5 |
8b68ba09d0328a7777a20f68eeedbcda
|
|
| BLAKE2b-256 |
2c04f3071042da872d0c68a76c547013a15acaf8de8ef848ca2d750fc517115c
|