A Python client library and CLI tools for accessing Infobús external APIs and integrating transit data into research workflows
Project description
Infobús Python Client
A Python client library and CLI tools for accessing Infobús external APIs and integrating transit data into research workflows.
Overview
The infobus package provides a simple and efficient way to interact with Infobús APIs, enabling researchers and developers to:
- Access real-time transit data from public transportation systems
- Retrieve historical transit information for analysis
- Integrate GTFS Realtime feeds into research workflows
- Query screen and display information
- Access weather and alert data associated with transit stops
Installation
# Install from PyPI (when available)
pip install infobus
# Install from source
pip install git+https://github.com/simovilab/infobus-py.git
# Development installation
git clone https://github.com/simovilab/infobus-py.git
cd infobus-py
pip install -e ".[dev]"
Quick Start
Python Library
from infobus import InfobusClient
# Initialize client
client = InfobusClient(base_url="https://your-infobus-instance.com")
# Get real-time transit data
transit_data = client.get_realtime_data()
# Query specific routes
route_info = client.get_route(route_id="route_123")
# Get screen information
screens = client.get_screens()
Command Line Interface
# Get help
infobus --help
# List available routes
infobus routes list
# Get real-time data for a specific route
infobus realtime --route-id route_123
# Export data to CSV
infobus export --format csv --output data.csv
Features
Core API Client
- RESTful API Integration: Clean interface to Infobús REST endpoints
- Authentication Support: Token-based authentication handling
- Error Handling: Comprehensive error handling with meaningful messages
- Rate Limiting: Built-in rate limiting and retry logic
Data Models
- Pydantic Models: Type-safe data models for all API responses
- GTFS Compatibility: Models aligned with GTFS and GTFS Realtime specifications
- Validation: Automatic data validation and serialization
CLI Tools
- Interactive Commands: Easy-to-use command-line interface
- Data Export: Export data in multiple formats (JSON, CSV, XML)
- Batch Operations: Process multiple requests efficiently
- Configuration Management: Store and manage API credentials
Research Integration
- Pandas Integration: Easy conversion to pandas DataFrames
- Time Series Support: Built-in support for time-based analysis
- Geospatial Data: Integration with geospatial libraries
Configuration
Create a configuration file at ~/.infobus/config.yaml:
api:
base_url: "https://your-infobus-instance.com"
token: "your-api-token"
timeout: 30
logging:
level: "INFO"
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
Development
Setup Development Environment
# Clone repository
git clone https://github.com/simovilab/infobus-py.git
cd infobus-py
# Install development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=infobus
# Run specific test file
pytest tests/test_client.py
Code Quality
# Format code
black src/ tests/
isort src/ tests/
# Type checking
mypy src/
# Run pre-commit checks
pre-commit run --all-files
API Reference
InfobusClient
The main client class for interacting with Infobús APIs.
class InfobusClient:
def __init__(self, base_url: str, token: str = None, timeout: int = 30)
def get_realtime_data(self, **filters) -> List[RealtimeData]
def get_routes(self) -> List[Route]
def get_route(self, route_id: str) -> Route
def get_screens(self) -> List[Screen]
def get_alerts(self) -> List[Alert]
Data Models
RealtimeData: Real-time transit informationRoute: Transit route informationScreen: Display screen informationAlert: Service alerts and notificationsWeather: Weather data for transit locations
Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Support
- Documentation: GitHub README
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Related Projects
- Infobús Server - The main Infobús Django application
- django-app-gtfs - GTFS data models for Django
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 infobus-0.1.0.tar.gz.
File metadata
- Download URL: infobus-0.1.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fbd5ddd4413d37b19748c2c22c12dc50b586191ed0bf83c1ed7ec6085e9096b
|
|
| MD5 |
2da868e08ff3e606d2991ea6460baac1
|
|
| BLAKE2b-256 |
bfd91b5c02d4ccf6ff90a96ba53c8e6472acccfdea6a126cc7c8bff7f58544aa
|
File details
Details for the file infobus-0.1.0-py3-none-any.whl.
File metadata
- Download URL: infobus-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b2e0ba92386b1c54a2d48ab0648dcadfd7a24e0fe7b5ae5db9830fda26c899e
|
|
| MD5 |
c4fdf10b10a4b6203378f2eb9a22d649
|
|
| BLAKE2b-256 |
5b142e05435c1f7653f8989825310bb198ebdb7139b7ec5e5f39dcf9d7465def
|