Skip to main content

Python wrapper for the Madrid EMT (Empresa Municipal de Transportes) API

Project description

EMTMadrid

PyPI License Python Version Ruff

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

  1. Clone the repository:

    git clone https://github.com/fermartv/EMTMadrid.git
    cd EMTMadrid
    
  2. 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

  1. Python 3.13.2 or higher
  2. An active EMT MobilityLabs account

Authentication

To use the EMT MobilityLabs API, you need to register on their official website. After registration:

  1. Complete the email verification process
  2. 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 coordinates
  • get_stop_info(): Returns the stop information

Data Models

BusArrival

Real-time bus arrival information including:

  • line: Bus line number
  • bus_id: Unique bus identifier
  • destination: Bus destination
  • coordinates: Bus GPS coordinates [longitude, latitude]
  • estimate_arrive_sec: Estimated arrival time in seconds
  • distance_bus: Distance to stop in meters
  • is_head: Whether this is the head bus
  • deviation: Route deviation in seconds
  • position_type_bus: Bus position type indicator

Stop

Bus stop information including:

  • stop_id: Unique stop identifier
  • stop_name: Stop name
  • stop_address: Stop address
  • stop_coordinates: Stop GPS coordinates [longitude, latitude]
  • stop_lines: List of Line objects serving this stop
  • bus_arrivals: List of BusArrival objects 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 dependencies
  • make update: Update dependencies
  • make test: Run tests
  • make test-coverage: Run tests with coverage report
  • make check-typing: Run static type checking
  • make check-lint: Check code style
  • make check-format: Check code formatting
  • make lint: Fix code style issues
  • make format: Format code
  • make 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:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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 lint and make format
  • Update the documentation if needed

License

This project is licensed under the GPLv3 - see the LICENSE file for details.

Acknowledgments

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

emt_madrid-1.1.0.tar.gz (74.0 kB view details)

Uploaded Source

Built Distribution

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

emt_madrid-1.1.0-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file emt_madrid-1.1.0.tar.gz.

File metadata

  • Download URL: emt_madrid-1.1.0.tar.gz
  • Upload date:
  • Size: 74.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for emt_madrid-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7ebfe7b7e985cc7cdae5dba4d0734b8c2e768a1eac5f8d03b8f0cf05e19f2076
MD5 f2a4007489f53ea7839047749ee0e265
BLAKE2b-256 fd764109ed9959aefe4f0139a2b2519f15666509e9d84564f0190355ba349247

See more details on using hashes here.

File details

Details for the file emt_madrid-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: emt_madrid-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for emt_madrid-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8211138ec5673566184e22d019d71ca1eadf3ba476b076cf58a529a22821f0e8
MD5 b57026d218493053e60ab96f50dc0037
BLAKE2b-256 c6b2a2f7eca7353a18326138397874e3e0d3c85fbba00cb9c940d2b60ea505b8

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