Python wrapper for Via Verde traffic camera images
Project description
🚗 ViaVerde Traffic API
A Python library to access Portuguese highway traffic camera images from the Via Verde website.
✨ Features
- 📷 Get camera images - Download traffic camera snapshots as bytes, PIL Images, or save directly to files
- 📍 List all cameras - Get metadata for all available traffic cameras including GPS coordinates
- 🔍 Search cameras - Find cameras by name or highway
- 🌐 Session management - Handles cookies and authentication automatically
- ⚡ Simple API - Easy to use with sensible defaults
📦 Installation
pip install viaverde-traffic
With Pillow support (for PIL Image objects)
pip install viaverde-traffic[pil]
For development
pip install viaverde-traffic[dev]
🚀 Quick Start
from viaverde_traffic import ViaVerdeTrafficAPI
# Initialize the API client
api = ViaVerdeTrafficAPI()
# Get list of all available cameras
cameras = api.get_all_cameras()
print(f"Found {len(cameras)} cameras")
# Get camera image and save to file
api.save_camera_image(camera_id=29, filepath="camera_29.jpg")
# Get camera image as bytes
image_bytes = api.get_camera_image(camera_id=29)
# Get camera image as PIL Image (requires Pillow)
img = api.get_camera_image_pil(camera_id=29)
img.show()
📖 API Reference
ViaVerdeTrafficAPI
The main client class for interacting with the Via Verde traffic API.
Constructor
api = ViaVerdeTrafficAPI(
language="PT", # Language code (default: "PT")
timeout=10, # Request timeout in seconds (default: 10)
user_agent=None, # Custom User-Agent string (optional)
)
Methods
get_all_cameras()
Get a list of all available cameras with metadata.
cameras = api.get_all_cameras()
for cam in cameras:
print(f"{cam['nomeAe']}: {cam['nomeCamara']} (ID: {cam['idCamara']})")
Returns a list of dictionaries with:
idCamara- Camera IDnomeCamara- Camera nameidAe- Highway IDnomeAe- Highway nameLatitude- GPS latitudeLongitude- GPS longitude
get_camera_image(camera_id)
Get camera image as bytes.
image_bytes = api.get_camera_image(camera_id=29)
with open("camera.jpg", "wb") as f:
f.write(image_bytes)
get_camera_image_pil(camera_id)
Get camera image as a PIL Image object. Requires Pillow.
img = api.get_camera_image_pil(camera_id=29)
print(f"Image size: {img.size}")
img.show()
save_camera_image(camera_id, filepath)
Save camera image directly to a file.
api.save_camera_image(camera_id=29, filepath="camera_29.jpg")
find_cameras(search)
Search for cameras by name or highway.
a1_cameras = api.find_cameras("A1")
print(f"Found {len(a1_cameras)} cameras on A1")
get_camera_by_id(camera_id)
Get a specific camera's metadata by ID.
camera = api.get_camera_by_id(29)
if camera:
print(f"Camera: {camera['nomeCamara']}")
get_camera_url(camera_id)
Get the direct URL for a camera image (requires session cookies).
url = api.get_camera_url(camera_id=29)
⚠️ Exception Handling
The library provides custom exceptions for better error handling:
from viaverde_traffic import (
ViaVerdeTrafficAPI,
ViaVerdeError,
ViaVerdeConnectionError,
ViaVerdeAPIError,
ViaVerdeImageError,
)
api = ViaVerdeTrafficAPI()
try:
cameras = api.get_all_cameras()
except ViaVerdeConnectionError as e:
print(f"Connection error: {e}")
except ViaVerdeAPIError as e:
print(f"API error: {e}")
except ViaVerdeError as e:
print(f"General error: {e}")
Exception Hierarchy
ViaVerdeError- Base exception for all errorsViaVerdeConnectionError- Network/connection errorsViaVerdeAPIError- API response errorsViaVerdeImageError- Image processing errors
📝 Examples
Download all cameras on a highway
from viaverde_traffic import ViaVerdeTrafficAPI
api = ViaVerdeTrafficAPI()
# Find all cameras on A1
a1_cameras = api.find_cameras("A1")
for camera in a1_cameras:
cam_id = camera['idCamara']
name = camera['nomeCamara'].replace(" ", "_")
filename = f"a1_{cam_id}_{name}.jpg"
api.save_camera_image(cam_id, filename)
print(f"Saved: {filename}")
Create a traffic monitor dashboard
from viaverde_traffic import ViaVerdeTrafficAPI
import time
api = ViaVerdeTrafficAPI()
# Monitor specific cameras every 5 minutes
camera_ids = [29, 30, 31]
while True:
for cam_id in camera_ids:
timestamp = int(time.time())
filename = f"camera_{cam_id}_{timestamp}.jpg"
api.save_camera_image(cam_id, filename)
print(f"Captured: {filename}")
time.sleep(300) # Wait 5 minutes
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repository
git clone https://github.com/mpoboas/viaverde-traffic-api.git
cd viaverde-traffic-api
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black viaverde_traffic/
ruff check viaverde_traffic/ --fix
# Type checking
mypy viaverde_traffic/
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
⚠️ Disclaimer
This library is an unofficial wrapper for the public Via Verde traffic information website. It is not affiliated with, endorsed by, or connected to Via Verde or Brisa Auto-Estradas de Portugal. Use responsibly and in accordance with Via Verde's terms of service.
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 viaverde_traffic-0.1.0.tar.gz.
File metadata
- Download URL: viaverde_traffic-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41a80e892ca8297155379f8a5fa7bd038635b7cf1aee4e67eec0d968aba43ea1
|
|
| MD5 |
e9c4bbff34e156b90f41e8a0e49b312c
|
|
| BLAKE2b-256 |
d6392fa0e9d035733517272ca0078f4c6ff0280ceb268f51f0eab3b6cd14a387
|
Provenance
The following attestation bundles were made for viaverde_traffic-0.1.0.tar.gz:
Publisher:
publish.yml on mpoboas/viaverde-traffic-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
viaverde_traffic-0.1.0.tar.gz -
Subject digest:
41a80e892ca8297155379f8a5fa7bd038635b7cf1aee4e67eec0d968aba43ea1 - Sigstore transparency entry: 787539248
- Sigstore integration time:
-
Permalink:
mpoboas/viaverde-traffic-api@5594c33202771ab2393a32b30b86acfc1de2a63c -
Branch / Tag:
refs/tags/v1.0 - Owner: https://github.com/mpoboas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5594c33202771ab2393a32b30b86acfc1de2a63c -
Trigger Event:
release
-
Statement type:
File details
Details for the file viaverde_traffic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: viaverde_traffic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4835bfa3575ba97e4f907d56964d92847370375aadd68225a528f952b0cc7f5
|
|
| MD5 |
2927d3758fd572e412a1dae0377a5802
|
|
| BLAKE2b-256 |
cea41b3d7d904df6640941b4c5769cefd3954b2d42b4783a49d42566fc82abe8
|
Provenance
The following attestation bundles were made for viaverde_traffic-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on mpoboas/viaverde-traffic-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
viaverde_traffic-0.1.0-py3-none-any.whl -
Subject digest:
c4835bfa3575ba97e4f907d56964d92847370375aadd68225a528f952b0cc7f5 - Sigstore transparency entry: 787539250
- Sigstore integration time:
-
Permalink:
mpoboas/viaverde-traffic-api@5594c33202771ab2393a32b30b86acfc1de2a63c -
Branch / Tag:
refs/tags/v1.0 - Owner: https://github.com/mpoboas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5594c33202771ab2393a32b30b86acfc1de2a63c -
Trigger Event:
release
-
Statement type: