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, geojson, lookup, and party endpoints.
Installation
uv add streetmanager
Usage
# Import the client modules
from streetmanager.work import swagger_client as work_client
from streetmanager.geojson import swagger_client as geojson_client
from streetmanager.lookup import swagger_client as lookup_client
from streetmanager.party import swagger_client as party_client
# Create API client instances
work_api = work_client.DefaultApi()
geojson_api = geojson_client.DefaultApi()
lookup_api = lookup_client.DefaultApi()
party_api = party_client.DefaultApi()
# Use the APIs
# Example: Get work details
work_response = work_api.get_work(work_id="123")
# Example: Get GeoJSON data
geojson_response = geojson_api.get_work_geojson(work_id="123")
# Example: Lookup street details
street_response = lookup_api.get_street(usrn="123456")
# Example: Get party details
party_response = party_api.get_party(party_id="123")
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
- GeoJSON API client for accessing geographical data
- Lookup API client for street information
- Party API client for managing party information
Requirements
- Python 3.12 or higher
- Dependencies are automatically installed with the package
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
streetmanager-0.1.6.tar.gz
(681.5 kB
view details)
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.1.6.tar.gz.
File metadata
- Download URL: streetmanager-0.1.6.tar.gz
- Upload date:
- Size: 681.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7049f9ff06ab65171381afcdc94fc22d877ed56d9f472c082a55f82daea521b
|
|
| MD5 |
db722421efe696b916c485a3bf26b91d
|
|
| BLAKE2b-256 |
af916edc59291ed13bff41af7236e8ceb24ba7e787e43023312e6cb96fed57bc
|
File details
Details for the file streetmanager-0.1.6-py3-none-any.whl.
File metadata
- Download URL: streetmanager-0.1.6-py3-none-any.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84414d6728ea954c7b548e15ac351c71dd7a1322fabef2b11ca60af4021d5fd2
|
|
| MD5 |
caaff0447e658ef379e3186caa04c77b
|
|
| BLAKE2b-256 |
e28979dbc095b452b47191bcce4fe1dbba0f88ee9b6978fe43f4b88932d72c96
|