pyptv3 - Access the Public Transport Victoria API with Python 3
pyptv3 is a Python library that provides a light wrapper around version 3 of the Public Transport Victoria (PTV) API.
The PTV Timetable API provides direct access to Public Transport Victoria’s public transport timetable data.
The API returns scheduled timetable, route and stop data for all metropolitan and regional train, tram and bus services in Victoria, including Night Network(Night Train and Night Tram data are included in metropolitan train and tram services data, respectively, whereas Night Bus is a separate route type).
The API also returns real-time data for metropolitan train, tram and bus services (where this data is made available to PTV), as well as disruption information, stop facility information, and access to myki ticket outlet data.
Getting Started
You will need a developer key from PTV. The instructions (in RTF format) are here, though if you can't be bothered downloading that, the TL;DR is to send an email to APIKeyRequest@ptv.vic.gov.au with the following information in the subject line of the email.
Installation
pip install pyptv3
Example
All API endpoints require a client object to be setup first. The client object takes your developer id and api key as arguments.
from pyptv3 import Client
client = Client("your developer id", "your api key")
As a general rule, required path parameters are passed as positional arguments, and optionals are passed as lists. See the swagger documentation for more information.
from pyptv3 import Client, Departures
client = Client("your developer id", "your api key")
departures = Departures(client, 0, 1341).by_route(4122, platform_numbers=[0, 1], direction_id=1, look_backwards=False, gtfs=123, date_utc="2018-06-28T07:00:00Z", max_results=10, include_cancelled=True, expand=["stop", "route"])
print(departures)
AsyncIO Example
There is a Async IO client if you want non-blocking behaviour
import asyncio
from pyptv3 import AsyncClient, Departures
loop = asyncio.get_event_loop()
client = AsyncClient(loop, "your developer id", "your api key")
def main():
departures = await Departures(client, 0, 1341).by_route(4122, platform_numbers=[0, 1], direction_id=1, look_backwards=False, gtfs=123, date_utc="2018-06-28T07:00:00Z", max_results=10, include_cancelled=True, expand=["stop", "route"])
print(departures)
loop.run_until_complete(main())
loop.close()
TODO
- pydoc
- Map the parsed JSON object to Python objects.
Metadata
Release files for pyptv3 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyptv3-0.0.4.tar.gz | 5.3 kB | Without provenance | Details for pyptv3-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyptv3-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for pyptv3-0.0.4-py3-none-any.whl |
Total release size: 15.0 kB
Release files / pyptv3-0.0.4.tar.gz
| Download URL | pyptv3-0.0.4.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
332d52fb9359cb516a851345dd7061526d5b9dcc53c3bc00c9accd83bea584e6
|
|
BLAKE2b-256 checksum How to use checksums |
b83f481f7217a6c6e7e6e762525a66131f560df0ef9de83bf7ac70860d89f354
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5
|
Release files / pyptv3-0.0.4-py3-none-any.whl
| Download URL | pyptv3-0.0.4-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e86280e08ec240bfc6330047b00e32df42db33060bb713d9db2c7efa1183498a
|
|
BLAKE2b-256 checksum How to use checksums |
9eac0e376903dee2eeb85b3e4ae4ea764b8cc39d590ef34024d48f1f16cf3fe9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5
|
Security for pyptv3 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.