Python wrapper for the Madrid EMT (Empresa Municipal de Transportes) API
Project description
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 informationget_stop_info(): Returns the stop information
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
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
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 emt_madrid-1.0.1.tar.gz.
File metadata
- Download URL: emt_madrid-1.0.1.tar.gz
- Upload date:
- Size: 70.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78112cd168bd2b8c5f19bc40a279dd4b3579014603eb77ce77fed185af0cf9f9
|
|
| MD5 |
db78c44c5d7e3db873073d3c04fbd94d
|
|
| BLAKE2b-256 |
0cb5af6671cc3e9e892e126099ec20a12e895063f34b7f969594e3eef9c341db
|
File details
Details for the file emt_madrid-1.0.1-py3-none-any.whl.
File metadata
- Download URL: emt_madrid-1.0.1-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b9ae0c21bb6e1fb025f8d2276240b111f4304b898dd16e30ec9e95b817d27cb
|
|
| MD5 |
e91e5b380fe98269dcdc8f3dd3264e5a
|
|
| BLAKE2b-256 |
34001ae48c1fae53d56914a4018788305d24b5465ebb2b9355f822ec52d7ba2d
|