A Python client library for the Street Manager API
Project description
Street Manager Python Client
A Python client library for the Street Manager API, providing access to work, reporting, lookup, geojson, party, export, event, and sampling endpoints.
Installation
uv add streetmanager
Usage
# Import the client modules
from streetmanager.work import swagger_client as work_client
from streetmanager.reporting import swagger_client as reporting_client
from streetmanager.lookup import swagger_client as lookup_client
from streetmanager.geojson import swagger_client as geojson_client
from streetmanager.party import swagger_client as party_client
from streetmanager.export import swagger_client as export_client
from streetmanager.event import swagger_client as event_client
from streetmanager.sampling import swagger_client as sampling_client
# Create API client instances
work_api = work_client.DefaultApi()
reporting_api = reporting_client.DefaultApi()
lookup_api = lookup_client.DefaultApi()
geojson_api = geojson_client.DefaultApi()
party_api = party_client.DefaultApi()
export_api = export_client.DefaultApi()
event_api = event_client.DefaultApi()
sampling_api = sampling_client.DefaultApi()
# Use the APIs
# Example: Get work details
work_response = work_api.get_work(work_id="123")
# Example: Get reporting data
reporting_data = reporting_api.get_activity_reporting()
# Example: Lookup street details
street_response = lookup_api.get_street(usrn="123456")
# Example: Get GeoJSON data
geojson_response = geojson_api.get_work_geojson(work_id="123")
# Example: Get party details
party_response = party_api.get_organisation(organisation_id="123")
# Example: Create CSV export
export_request = export_client.PermitCSVExportRequest()
export_response = export_api.create_permit_csv_export(permit_csv_export_request=export_request)
# Example: Get works updates
works_updates = event_api.get_works_updates()
# Example: Get sampling data
sampling_data = sampling_api.get_sample_inspection_targets()
Authentication
To authenticate with the Street Manager API, you'll need to provide your credentials and use the authentication flow:
import os
from streetmanager.work import swagger_client as streetmanager_client
from streetmanager.work.swagger_client.rest import ApiException
class StreetManagerAPI:
def __init__(self, base_url: str, username: str, password: str):
self.base_url = base_url
self.username = username
self.password = password
self.auth_response = self._perform_authentication()
def _perform_authentication(self):
# Initial configuration for authentication
configuration = streetmanager_client.Configuration()
configuration.host = self.base_url
# Create API client for authentication
api_client = streetmanager_client.ApiClient(configuration)
auth_api_instance = streetmanager_client.DefaultApi(api_client)
# Create authentication request
auth_request = streetmanager_client.AuthenticationRequest(
email_address=self.username, password=self.password
)
try:
response = auth_api_instance.authenticate(auth_request)
return response
except ApiException as e:
if e.body:
print("Response body:", e.body)
raise
def get_api_instance(self) -> streetmanager_client.DefaultApi:
if not self.auth_response:
raise Exception("Authentication response not available. Ensure authentication was successful.")
# Create a new configuration for the specific API calls
configuration = streetmanager_client.Configuration()
configuration.host = self.base_url
# Configure for id_token
configuration.api_key["token"] = self.auth_response.id_token
configuration.api_key_prefix["token"] = ""
# Create API client with the token-specific configuration
api_client = streetmanager_client.ApiClient(configuration)
return streetmanager_client.DefaultApi(api_client)
# Configuration
BASE_URL = "https://api.sandbox.manage-roadworks.service.gov.uk/v6/work"
USERNAME = "your-email@example.com"
PASSWORD = os.getenv("STREETMANAGER_PASSWORD") # Store your password securely in environment variables
# Initialize the API Handler
sm_api_handler = StreetManagerAPI(BASE_URL, USERNAME, PASSWORD)
# Get an authenticated API instance
api_instance = sm_api_handler.get_api_instance()
# Now you can use the API instance for authenticated requests
work_response = api_instance.get_work(work_id="123")
Features
- Work API client for managing street works
- Reporting API client for reporting functionality
- Lookup API client for street information
- GeoJSON API client for accessing geographical data
- Party API client for managing party information
- Export API client for data export functionality
- Event API client for getting works updates
- Sampling API client for sampling functionality
Requirements
- Python 3.12 or higher
- Dependencies are automatically installed with the package
API Documentation
The following Swagger documentation URLs are available for each API:
Releasing
- Bump version in
pyproject.toml(PEP 440). - Commit and push to
main. - Create a GitHub Release for tag
vX.Y.Zincogna-public/streetmanager(the tag can be created in the Release UI). - The GitHub Actions workflow builds wheels/sdist with
uv buildand publishes to PyPI via Trusted Publishing (no token required).
Quick release with Just
Use the Justfile recipe to bump, tag, push, and create the GitHub Release:
just release # bump patch
just release minor # bump minor
just release major "Notes" # bump major with release notes
Notes
- Requires
ghCLI authenticated (gh auth status). - Uses
uv version --bumpto updatepyproject.tomland tagsvX.Y.Z.
First-time setup on PyPI
- In PyPI project
streetmanager→ Settings → Publishing → addcogna-public/streetmanageras a Trusted Publisher (GitHub Actions), or approve the pending publisher after first run.
Verify
- PyPI project page: https://pypi.org/project/streetmanager/
Changelog
- See CHANGELOG.md for notable changes and release notes.
- GitHub Releases: https://github.com/cogna-public/streetmanager/releases
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 streetmanager-0.3.2.tar.gz.
File metadata
- Download URL: streetmanager-0.3.2.tar.gz
- Upload date:
- Size: 658.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
243111d1f4759ac0c6f4317a39c40c23d21f6e0fa09e4a8229386e030de4b44b
|
|
| MD5 |
9868915c3af3fa54901e46c000939337
|
|
| BLAKE2b-256 |
9501a87f23b4bb15c36dfb16b8cec227e999d4adb7a4351eb83a02e3d2666573
|
Provenance
The following attestation bundles were made for streetmanager-0.3.2.tar.gz:
Publisher:
publish.yml on cogna-public/streetmanager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
streetmanager-0.3.2.tar.gz -
Subject digest:
243111d1f4759ac0c6f4317a39c40c23d21f6e0fa09e4a8229386e030de4b44b - Sigstore transparency entry: 483943994
- Sigstore integration time:
-
Permalink:
cogna-public/streetmanager@339c2faa57f8198096006966dad9febe3ab84c34 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/cogna-public
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@339c2faa57f8198096006966dad9febe3ab84c34 -
Trigger Event:
release
-
Statement type:
File details
Details for the file streetmanager-0.3.2-py3-none-any.whl.
File metadata
- Download URL: streetmanager-0.3.2-py3-none-any.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e061816b1444c2c901c444663a504eaf3fe021fb7eae7541d2e488ddbf552b0
|
|
| MD5 |
fa77c896b9b6dbec7ef2b95b7e38d620
|
|
| BLAKE2b-256 |
4c62b7c60ef6796d2771519f41d6343a978d500cc1e90b5ddc4e5fc7d648f7c1
|
Provenance
The following attestation bundles were made for streetmanager-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on cogna-public/streetmanager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
streetmanager-0.3.2-py3-none-any.whl -
Subject digest:
5e061816b1444c2c901c444663a504eaf3fe021fb7eae7541d2e488ddbf552b0 - Sigstore transparency entry: 483944004
- Sigstore integration time:
-
Permalink:
cogna-public/streetmanager@339c2faa57f8198096006966dad9febe3ab84c34 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/cogna-public
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@339c2faa57f8198096006966dad9febe3ab84c34 -
Trigger Event:
release
-
Statement type: