Skip to main content

A Python client for Norwegian traffic data

Project description

PyTrafikk

A Python client and web application for accessing Norwegian traffic data from the Norwegian Public Roads Administration (Statens vegvesen).

Features

  • Query traffic registration points across Norway
  • Filter by road categories (European, National, County, Municipal, Private)
  • Interactive map view showing all measurement points
  • Time series analysis with:
    • Hourly and daily traffic volume data
    • Interactive plots
    • Date range selection
    • Station search

Installation

# Clone the repository
git clone https://github.com/yourusername/pytrafikk.git
cd pytrafikk

# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install the package and dependencies
pip install -e .

Usage

Web Application

Start the Flask development server:

flask --app pytrafikk.web.app run

Then open http://localhost:5000 in your browser to access:

  • Interactive map view at /map
  • Time series analysis at /timeseries

Python API

from pytrafikk.client import (
    query_traffic_registration_points,
    query_traffic_volume,
    query_traffic_volume_by_day
)

# API base URL
BASE_URL = "https://trafikkdata-api.atlas.vegvesen.no/"

# Get all European highway measurement points
points = query_traffic_registration_points(BASE_URL, "E")

# Query hourly traffic volume for a point
volumes = query_traffic_volume(
    BASE_URL,
    point_id="97411V72313",  # Example: E6 Mortenhals
    from_time="2024-01-01T00:00:00+01:00",
    to_time="2024-01-02T00:00:00+01:00"
)

# Query daily traffic volume
daily = query_traffic_volume_by_day(
    BASE_URL,
    point_id="97411V72313",
    from_time="2024-01-01T00:00:00+01:00",
    to_time="2024-01-07T00:00:00+01:00"
)

Development

Running Tests

Tests are written using pytest and can be run with:

pytest

Project Structure

pytrafikk/
├── __init__.py
├── client.py          # Core API client
├── explore.py         # Road category analysis tools
├── tests/
│   └── test_client.py # API client tests
└── web/              # Flask web application
    ├── app.py
    └── templates/
        ├── index.html
        ├── map.html
        └── timeseries.html

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

pytrafikk-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

pytrafikk-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file pytrafikk-0.1.0.tar.gz.

File metadata

  • Download URL: pytrafikk-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for pytrafikk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c1fb1e2bc261de4d1c07ae80bc20e03fc0203fd883f61bb52680854fbeffe66f
MD5 75713b4afe7214da36dd315bda8d459c
BLAKE2b-256 21ec5296455497894d9f4162ba5e671f405ce230fa2418400d72d10ee151aac2

See more details on using hashes here.

File details

Details for the file pytrafikk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytrafikk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for pytrafikk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4301ad4b874231138227e75f73b78df9eb2002c334784779afbfae4242884c3c
MD5 c08de21746a8aa1772f21860313326a5
BLAKE2b-256 2a941fbceb385a781bbfc7df98bed5c183434e2388a5161218267166f15b2beb

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