Skip to main content

No project description provided

Project description

Unofficial MVG api

An async and sync wrapper for the MVG endpoints, with data validation over pydantic

Breaking Changes

MVG changed the api again. Currently only a few endpoints work in v1 and v2.

between version 0.1.5 and 0.2.0 the api has changed a lot. The api is now split into versions. The old api is available under mvg_api.v1 and the new api is available under mvg_api.v2.

Features

  • Sync and async support: You can use this wrapper to make API calls synchronously or asynchronously based on your needs. It provides flexibility and allows you to leverage the benefits of both approaches.

  • Pydantic schema validation: The wrapper integrates with Pydantic, a powerful data validation and parsing library, to validate API responses against predefined schemas. This ensures that the received data conforms to the expected structure and types. For every API endpoint, there is a corresponding Pydantic schema that defines the expected structure of the response. If the response does not match the schema, an exception is raised. And you always know what data you get.

Installation

Install it over pip or from source by cloning the repository and installing the dependencies with uv.

pip install async-mvg-api

or

git clone https://github.com/Plutokekz/MVG-Api.git
cd MVG-Api
uv sync

Usage

With the endpoint changes from MVG the api is now split into versions. Currently, there are two versions available. The first version is the old api, which is still available and works, but I think in the future it may stop working and will be removed.

The second version is the new api, which is still in beta, should work until MVG changes their endpoints one again.

Documentation of v2 endpoints

Endpoints

Method: get_ticker

def get_ticker(self) -> ems.Messages

Get ticker messages, updates about the disruptions and planed works on the MVG train network There 2 types of messages DISRUPTION and PLANNED

  • Returns a list of ticker messages containing updates about disruptions and planned works on the MVG train network.

Method: get_station

def get_station(self, station_id: str) -> station.Station

Get a station by its id the Station id can be found in the get_all_stations list, or it can be obtained from a location method when the found Location is of the type STATION

  • Parameters:
    • station_id: The ID of the station.
  • Returns a station.Station object representing the station information.

Method: get_escalators_and_elevators

def get_escalators_and_elevators(self, efa_id: int) -> transportdevice.StationTransportDevices

Get the escalators and elevators location and status for a station

  • Parameters:
    • efa_id: an integer number that is associated with a station. It is included in the Station object but under the name of divId for some reason.
  • Returns a transportdevice.StationTransportDevices object representing the escalators and elevators at the station.

Method: get_aushang

def get_aushang(self, plan_id: str) -> aushang.Aushaenge

Get the aushang for a station, get all Playn that a currently active in a stations' blackboard.

  • Parameters:
    • plan_id: I am not sure bit it seems to be the first 2 letters of the station name in uppercase. For example, KA for Karlsplatz
  • Returns a aushang.Aushaenge object representing the aushang (playn) currently active at the station.

Method: get_station_ids

def get_station_ids(self) -> List[str]

Get all the station ids

  • Returns a list of all station IDs available.

Tests

uv run pytest mvg_api/v1/tests/api_tests.py mvg_api/v2/tests/api_tests.py

Credit

For Endpoint Information and Code snippets

Usage policy of the MVG api

ACHTUNG:

Unsere Systeme dienen der direkten Kundeninteraktion. Die Verarbeitung unserer Inhalte oder Daten durch Dritte erfordert unsere ausdrückliche Zustimmung. Für private, nicht-kommerzielle Zwecke, wird eine gemäßigte Nutzung ohne unsere ausdrückliche Zustimmung geduldet. Jegliche Form von Data-Mining stellt keine gemäßigte Nutzung dar. Wir behalten uns vor, die Duldung grundsätzlich oder in Einzelfällen zu widerrufen. Fragen richten Sie bitte gerne an: redaktion@mvg.de.

In other words: Private, noncommercial, moderate use of the API is tolerated. They do not consider data mining as a moderate use.

(Disclaimer: I am not a lawyer, this is not legal advice)

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

async_mvg_api-0.2.8.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

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

async_mvg_api-0.2.8-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file async_mvg_api-0.2.8.tar.gz.

File metadata

  • Download URL: async_mvg_api-0.2.8.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for async_mvg_api-0.2.8.tar.gz
Algorithm Hash digest
SHA256 8f69b3d3591b18ebce6ae3dbddf5b988efe10ca6d5064fbaa5a322b44bbb3171
MD5 65f554946d5ed9c8a29746e339ba1bd5
BLAKE2b-256 22ca3f86a2aca80811a4266c0dff561194b38d6bc279e3e29ee11c1a8be3763e

See more details on using hashes here.

File details

Details for the file async_mvg_api-0.2.8-py3-none-any.whl.

File metadata

File hashes

Hashes for async_mvg_api-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 063b6461bced63776d1ad1d2a61af1f443d4c14c20a300013081d9ee636a17a8
MD5 ebff2ecac2481f3b3a20c3d0ce39a652
BLAKE2b-256 8414b6bec4d9eb243a133c17d7a0ed64b7ba4a4163ac9b46654e891ad8056110

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