EMTMadrid
A modern, asynchronous Python wrapper for the Madrid EMT (Empresa Municipal de Transportes) API, providing easy access to real-time public transportation data in Madrid, Spain.
Features
- Real-time bus arrival information
- Stop information and details
- Simple and intuitive interface
- Asynchronous API client using
aiohttp - Type hints for better development experience
- Modern Python 3.13+ codebase
- Comprehensive test suite
- Code quality tools pre-configured
Installation
Using pip
Install the package from PyPI:
pip install emt-madrid
Development Setup
-
Clone the repository:
git clone https://github.com/fermartv/EMTMadrid.git cd EMTMadrid
-
Set up the development environment:
make local-setup source .venv/bin/activate
This will:
- Install Python 3.13.2 using uv
- Set up pre-commit hooks
- Install all dependencies
- Activate the virtual environment
Usage
Prerequisites
- Python 3.13.2 or higher
- An active EMT MobilityLabs account
Authentication
To use the EMT MobilityLabs API, you need to register on their official website. After registration:
- Complete the email verification process
- Note your login credentials (email and password)
Basic Example
import asyncio
from aiohttp import ClientSession
from emt_madrid import EMTClient
async def main():
# Replace these with your actual credentials
EMAIL = "your-email@example.com"
PASSWORD = "your-password"
STOP_ID = "72" # Example stop ID
async with ClientSession() as session:
# Create EMT client
emt_client = EMTClient(
email=EMAIL,
password=PASSWORD,
stop_id=STOP_ID,
session=session,
)
# Fetch stop information and arrivals
arrivals = await emt_client.get_arrivals()
# Get and display the data
print("Stop Information:", arrivals)
if __name__ == "__main__":
asyncio.run(main())
More examples can be found in the example directory. Run them with:
make run-example
Available Methods
EMTClient
get_arrivals(): Fetches and updates stop information including bus arrivals with coordinatesget_stop_info(): Returns the stop information
Data Models
BusArrival
Real-time bus arrival information including:
line: Bus line numberbus_id: Unique bus identifierdestination: Bus destinationcoordinates: Bus GPS coordinates[longitude, latitude]estimate_arrive_sec: Estimated arrival time in secondsdistance_bus: Distance to stop in metersis_head: Whether this is the head busdeviation: Route deviation in secondsposition_type_bus: Bus position type indicator
Stop
Bus stop information including:
stop_id: Unique stop identifierstop_name: Stop namestop_address: Stop addressstop_coordinates: Stop GPS coordinates[longitude, latitude]stop_lines: List ofLineobjects serving this stopbus_arrivals: List ofBusArrivalobjects with real-time arrival data and coordinates
Development
Project Structure
EMTMadrid/
├── emt_madrid/ # Main package source code
├── tests/ # Test files
├── example/ # Example scripts
├── pyproject.toml # Project configuration
└── Makefile # Development commands
Available Commands
make install: Install all dependenciesmake update: Update dependenciesmake test: Run testsmake test-coverage: Run tests with coverage reportmake check-typing: Run static type checkingmake check-lint: Check code stylemake check-format: Check code formattingmake lint: Fix code style issuesmake format: Format codemake pre-commit: Run all checks and tests (used in CI)make run-example: Run the basic example
Adding Dependencies
-
For development dependencies:
make add-dev-package package=package-name
-
For production dependencies:
make add-package package=package-name
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Before submitting your PR, please make sure to:
- Run all tests with
make test - Ensure code style is consistent with
make lintandmake format - Update the documentation if needed
License
This project is licensed under the GPLv3 - see the LICENSE file for details.
Acknowledgments
- EMT Madrid MobilityLabs for providing the API
- API Documentation
Metadata
Release files for emt-madrid 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| emt_madrid-1.1.1.tar.gz | 81.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| emt_madrid-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 109.6 kB
Release files / emt_madrid-1.1.1.tar.gz
| Download URL | emt_madrid-1.1.1.tar.gz |
|---|---|
| Size | 81.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdc3d9d91b770981277b0fc99d61c67144313a6f84fbbbec27a165a2af8260d7
|
|
BLAKE2b-256 checksum How to use checksums |
608784955e4bbbf0465c2ef10a9e87c9aac48c9f9f80d8e3145ce7bf7b6a04f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / emt_madrid-1.1.1-py3-none-any.whl
| Download URL | emt_madrid-1.1.1-py3-none-any.whl |
|---|---|
| Size | 28.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ddb442bb87eab78dff535b654c9bc51b05d14d0a16e9d641143bb8d3a9b918a
|
|
BLAKE2b-256 checksum How to use checksums |
6dd5ab8dfe54053cc64079ffdc892f0c50ec00df2afca71dc5f6b48d7228c505
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|