A Python client library for interacting with the Autoskope vehicle tracking API.
- Async/await support using aiohttp
- Session management with cookie isolation
- Context manager support for automatic cleanup
- Type hints for better IDE support
- Comprehensive error handling
pip install autoskope-clientimport asyncio
from autoskope_client import AutoskopeApi
async def main():
async with AutoskopeApi(
host="https://portal.autoskope.de",
username="your_username",
password="your_password"
) as api:
# Get all vehicles
vehicles = await api.get_vehicles()
for vehicle in vehicles:
print(f"Vehicle: {vehicle.name}")
if vehicle.position:
print(f" Location: {vehicle.position.latitude}, {vehicle.position.longitude}")
print(f" Speed: {vehicle.position.speed} km/h")
asyncio.run(main())import asyncio
from autoskope_client import AutoskopeApi
async def main():
api = AutoskopeApi(
host="https://portal.autoskope.de",
username="your_username",
password="your_password"
)
try:
await api.connect()
vehicles = await api.get_vehicles()
for vehicle in vehicles:
print(f"Vehicle: {vehicle.name}")
finally:
await api.close()
asyncio.run(main())import asyncio
from autoskope_client import AutoskopeApi
async def main():
# Set custom timeout (default is 20 seconds)
async with AutoskopeApi(
host="https://portal.autoskope.de",
username="your_username",
password="your_password",
timeout=30 # Custom timeout in seconds
) as api:
vehicles = await api.get_vehicles()
print(f"Found {len(vehicles)} vehicles")
asyncio.run(main())import asyncio
import aiohttp
from autoskope_client import AutoskopeApi
async def main():
async with aiohttp.ClientSession() as session:
api = AutoskopeApi(
host="https://portal.autoskope.de",
username="your_username",
password="your_password",
session=session # Use external session
)
await api.connect()
vehicles = await api.get_vehicles()
asyncio.run(main())id: Unique identifiername: Vehicle namemodel: Vehicle modelbattery_voltage: Battery voltage in voltsexternal_voltage: External power voltage in voltsgps_quality: GPS quality (HDOP - lower is better)imei: Device IMEIposition: Current position (if available)
latitude: Latitude coordinatelongitude: Longitude coordinatespeed: Speed in km/htimestamp: Position timestamppark_mode: Whether vehicle is parked
The library defines two main exception types:
InvalidAuth: Raised when authentication failsCannotConnect: Raised when connection to the API fails
from autoskope_client import AutoskopeApi, InvalidAuth, CannotConnect
try:
async with AutoskopeApi(...) as api:
vehicles = await api.get_vehicles()
except InvalidAuth:
print("Authentication failed. Check credentials.")
except CannotConnect:
print("Could not connect to Autoskope API.")- Python 3.8+
- aiohttp >= 3.8.0
Install test dependencies:
pip install -e ".[test]"Run unit tests only (no API calls):
pytest -v -m "not integration"Run all tests including integration tests (requires credentials):
# Set environment variables first
export AUTOSKOPE_HOST=https://portal.autoskope.de
export AUTOSKOPE_USERNAME=your_username
export AUTOSKOPE_PASSWORD=your_password
# Run all tests
pytest -vRun tests with coverage:
pytest --cov=autoskope_client --cov-report=htmlIntegration tests make real API calls and require valid credentials. They are marked with @pytest.mark.integration and will be skipped automatically if credentials are not set.
Secure way to run integration tests (recommended):
# Option 1: Using the secure test runner (password hidden)
python run_integration_tests.py
# Option 2: Using .env file
cp .env.example .env
# Edit .env with your credentials
pip install python-dotenv
python run_integration_tests.pyTo run only integration tests:
pytest -v -m integrationSecurity Note: Never commit credentials to git. The .env file is excluded via .gitignore.
Nico Liebeskind (nico@autoskope.de)