Configuration & exceptions#

SGUConfig

Configuration settings for SGU API client.

SGUClientError

Base exception for all SGU client errors.

SGUAPIError

Raised when the SGU API returns an error response.

SGUConnectionError

Raised when connection to SGU API fails.

SGUTimeoutError

Raised when a request to SGU API times out.

SGUValidationError

Raised when data validation fails.

SGUNotFoundError

Raised when a lookup matches no feature.

SGUAmbiguousError

Raised when a lookup that expects one feature matches several.

Configuration#

Pass an SGUConfig to SGUClient to change timeouts, retries or logging. The configuration is immutable once created.

timeout, max_retries and user_agent configure the default RequestsTransport. A transport you pass to SGUClient(transport=...) doesn’t use them (see Client).

pydantic model SGUConfig[source]#

Configuration settings for SGU API client.

field base_url: str = 'https://api.sgu.se/oppnadata/'#

Root URL of the SGU open data APIs; every dataset is found below it

field timeout: float = 30.0#

Request timeout in seconds

Constraints:
  • ge = 1.0

field max_retries: int = 3#

Maximum number of retry attempts

Constraints:
  • ge = 0

field user_agent: str = 'sgu-client/0.1.0'#

User-Agent header for requests

field log_level: str | int | None = 'WARNING'#

Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL or numeric value). Set to None to disable logging configuration and manage it yourself.

Exceptions#

All exceptions raised by the client inherit from SGUClientError, so catching it handles every client error:

SGUClientError
├── SGUAPIError         the API returned an error response
├── SGUConnectionError  the connection to the API failed
├── SGUTimeoutError     the request timed out
├── SGUValidationError  data validation failed
├── SGUNotFoundError    a lookup matched nothing (also a ValueError)
└── SGUAmbiguousError   a lookup expecting one feature matched several
                        (also a ValueError)
exception SGUClientError[source]#

Base exception for all SGU client errors.

exception SGUAPIError(message, status_code=None, response_data=None)[source]#

Raised when the SGU API returns an error response.

exception SGUConnectionError[source]#

Raised when connection to SGU API fails.

exception SGUTimeoutError[source]#

Raised when a request to SGU API times out.

exception SGUValidationError[source]#

Raised when data validation fails.

exception SGUNotFoundError[source]#

Raised when a lookup matches no feature.

Subclasses ValueError so code that catches ValueError keeps working.

exception SGUAmbiguousError[source]#

Raised when a lookup that expects one feature matches several.

Subclasses ValueError so code that catches ValueError keeps working.