An unofficial python client for Barcelona public transport (TMB) API.
Project description
PyTMB
Unofficial Python client for the Barcelona public transport (TMB) API.
This library is not affiliated with TMB. Use responsibly and respect the API Terms of Service.
Features
- Bus ETA lookup (
IBusClient.get_eta) - Metro ETA lookup (
IMetroClient.get_eta) - Optional filtering by line
- Pydantic models for structured responses
- Simple, synchronous API using
requests
Requirements
- Python >= 3.10
Installation
PyPI:
pip install pytmb
From source (clone this repository):
pip install .
API Credentials
You need an app_id and app_key from TMB's developer portal.
Register at: https://developer.tmb.cat/
Quick Start
from pytmb.iBus import IBusClient
from pytmb.iMetro import IMetroClient
BUS_STOP_CODE = "1234" # Replace with a real stop code
METRO_STATIONS = ["123", "456"] # Replace with real station codes
app_id = "YOUR_APP_ID"
app_key = "YOUR_APP_KEY"
# Bus ETA
bus_client = IBusClient(app_id=app_id, app_key=app_key)
bus_etas = bus_client.get_eta(BUS_STOP_CODE, line="H10") # Optionally filter by line
for eta in bus_etas:
print(f"Bus {eta.line_name} to {eta.destination} arriving in {eta.eta_minutes} min (ramp={eta.ramp_status})")
# Metro ETA
metro_client = IMetroClient(app_id=app_id, app_key=app_key)
metro_etas = metro_client.get_eta(METRO_STATIONS, line="L1")
for eta in metro_etas:
print(f"Metro {eta.line_name} to {eta.destination} arriving in {eta.eta_minutes} min at station {eta.station_code}")
Roadmap / Ideas
- Coverage for more TMB endpoints
License
See LICENSE file.
Disclaimer
All trademarks and data belong to TMB. This is a community project.
Project details
Release history Release notifications | RSS feed
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 pytmb-0.1.0b3.tar.gz.
File metadata
- Download URL: pytmb-0.1.0b3.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12d107924d507c104e9594d4a30f319facd09b6543b19de867b516b3a918119a
|
|
| MD5 |
c5fd5e8ef1d1607c3c8d38f14f76c53a
|
|
| BLAKE2b-256 |
22c92b8038778fce459650001333409d6202c218b040d26306b96e9cb0f430e0
|
File details
Details for the file pytmb-0.1.0b3-py3-none-any.whl.
File metadata
- Download URL: pytmb-0.1.0b3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bd274b936ab2c5ce7105b5370985c12b39333355ec396945f014aac9908b565
|
|
| MD5 |
17e16d8d7b0d7cfcf9978b4c6f9395b0
|
|
| BLAKE2b-256 |
168ac3e7ad59aa6be6e8d3de4ad559eb5688645d2a75015e5d87dd10de482daf
|