Base¶
Client¶
NBG base client module. This is used internally to create clients for all supported NBG APIs.
-
class
nbg.base.client.
BaseClient
(client_id: str, client_secret: str, production: bool = False)¶
Decorators¶
-
nbg.base.decorators.
api_call
(method: callable)¶ Mark a client method as an API call. This enables each NBG API client to serialise server responses, based on the provided type annotations.
Environment¶
Utilities for managing NBG API requests to both production and sandbox environments.
-
class
nbg.base.environment.
EnvironmentClientMixin
¶ Enables sending requests to both production and sandbox APIs and also targeting requests to particular sandboxes.
-
property
application_id
¶ In production mode, it returns the client_id of the client, or else it always returns 72F01708-BE1E-4567-926E-8C87D03CA551.
-
property
base_url
¶ Returns the base URL of the current client according to the configured environment.
-
property
consent_base_url
¶ Returns the consent base URL of the current client according to the configured environment.
-
create_sandbox
(sandbox_id: str) → dict¶ Create a sandbox with the given
sandbox_id
.- Parameters
sandbox_id (string) – The unique ID of the sandbox to be created.
— Usage
client.create_sandbox("my-unique-sandbox-id")
-
delete_sandbox
(sandbox_id: str) → bool¶ Deletes the sandbox identified by the given sandbox_id.
- Parameters
sandbox_id (string) – The unique ID of the sandbox to delete.
— Usage
client.delete_sandbox("my-unique-sandbox-id")
-
property
environment_headers
¶ Returns the required headers to execute a request in the configured sandbox.
-
export_sandbox
(sandbox_id: str) → dict¶ Returns all contents of the sandbox identified by the given sandbox_id.
- Parameters
sandbox_id (string) – The unique ID of the sandbox to get its data.
— Usage
client.export_sandbox("my-unique-sandbox-id")
-
import_sandbox
(sandbox_id: str, data: dict) → dict¶ Imports the given data into the sandbox identified by the given sandbox_id.
- Parameters
sandbox_id (string) – The unique ID of the sandbox into which to import data.
data (dict) – The JSON data to import into the sandbox
— Usage
sandbox_data = {"sandbox": "data", "key": "value"} client.import_sandbox("my-unique-sandbox-id", sandbox_data)
-
property
scopes
¶ Returns the required OAuth scopes of the current client API according to the configured environment.
-
set_sandbox
(sandbox_id: str)¶ Sets the sandbox ID to be used by the current client.
- Parameters
sandbox_id (string) – The unique ID of the sandbox to use in subsequent API requests.
— Usage
client.set_sandbox("my-unique-sandbox-id")
-
property
Utils¶
Generic utilities used by the base client of all NBG APIs.
-
nbg.base.utils.
serialize_request_payload
(data: dict) → dict¶ Serializes the request payload to match the format requested by NBG APIs. Serializations:
datetime: (Z-suffixed ISO format)
-
nbg.base.utils.
validate_response
(response: requests.models.Response) → dict¶ Validates that the given response is valid JSON and it contains all required fields.