ds_protocol_http_py_lib

A Python package from the ds-protocol library collection.

File: __init__.py Region: ds-protocol-http-py-lib

Example:

from ds_protocol_http_py_lib import __version__

print(f"Package version: {__version__}")

Submodules

Attributes

__version__

Classes

HttpDataset

Tabular dataset object which identifies data within a data store,

HttpDatasetSettings

Settings for HTTP dataset.

HttpLinkedService

The class is used to connect with HTTP API.

HttpLinkedServiceSettings

Settings for HTTP linked service connections.

Package Contents

ds_protocol_http_py_lib.__version__
class ds_protocol_http_py_lib.HttpDataset[source]

Bases: ds_resource_plugin_py_lib.common.resource.dataset.TabularDataset[HttpLinkedServiceType, HttpDatasetSettingsType, ds_resource_plugin_py_lib.common.serde.serialize.PandasSerializer, ds_resource_plugin_py_lib.common.serde.deserialize.PandasDeserializer], Generic[HttpLinkedServiceType, HttpDatasetSettingsType]

Tabular dataset object which identifies data within a data store, such as table/csv/json/parquet/parquetdataset/ and other documents.

The input of the dataset is a pandas DataFrame. The output of the dataset is a pandas DataFrame.

linked_service: HttpLinkedServiceType
settings: HttpDatasetSettingsType
serializer: ds_resource_plugin_py_lib.common.serde.serialize.PandasSerializer | None
deserializer: ds_resource_plugin_py_lib.common.serde.deserialize.PandasDeserializer | None
property type: ds_protocol_http_py_lib.enums.ResourceType

Get the type of the dataset.

_resolve_url() str[source]

Resolve the URL by substituting any path parameters.

create() None[source]

Create data at the specified endpoint.

Parameters:

kwargs – Additional keyword arguments to pass to the request.

Raises:
  • AuthenticationError – If the authentication fails.

  • AuthorizationError – If the authorization fails.

  • ConnectionError – If the connection fails.

  • CreateError – If the create error occurs.

read() None[source]

Read data from the specified endpoint.

Parameters:

kwargs – Additional keyword arguments to pass to the request.

Raises:
  • AuthenticationError – If the authentication fails.

  • AuthorizationError – If the authorization fails.

  • ConnectionError – If the connection fails.

  • ReadError – If the read error occurs.

delete() NoReturn[source]

Delete entity using http.

update() NoReturn[source]

Update entity using http.

rename() NoReturn[source]

Rename entity using http.

upsert() NoReturn[source]

Upsert entity using http.

purge() NoReturn[source]

Purge entity using http.

list() NoReturn[source]

List entity using http.

_map_files(files: collections.abc.Sequence[ds_protocol_http_py_lib.models.Files] | None) Any[source]

Convert typed Files descriptors into requests compatible files=….

HttpDatasetSettings.files is expected to already be deserialized into the correct typed model, so this method focuses purely on the requests shape conversion.

close() None[source]

Close the dataset.

class ds_protocol_http_py_lib.HttpDatasetSettings[source]

Bases: ds_resource_plugin_py_lib.common.resource.dataset.DatasetSettings

Settings for HTTP dataset.

method: ds_protocol_http_py_lib.enums.HttpMethod

The HTTP method to use.

url: str

The URL to send the request to.

data: Any | None = None

The data to send with the request.

json: dict[str, Any] | None = None

The JSON data to send with the request.

params: dict[str, Any] | None = None

The parameters to send with the request.

files: list[ds_protocol_http_py_lib.models.Files] | None = None

The multipart files to send with the request.

headers: dict[str, Any] | None = None

The headers to send with the request.

path_params: dict[str, Any] | None = None

Path parameters to interpolate into the URL template using {param} syntax.

Example

url=”https://api.example.com/documents/{document_guid}/original” path_params={“document_guid”: “abc123”} # → https://api.example.com/documents/abc123/original

class ds_protocol_http_py_lib.HttpLinkedService[source]

Bases: ds_resource_plugin_py_lib.common.resource.linked_service.LinkedService[HttpLinkedServiceSettingsType], Generic[HttpLinkedServiceSettingsType]

The class is used to connect with HTTP API.

settings: HttpLinkedServiceSettingsType
_session: ds_protocol_http_py_lib.utils.http.provider.Http | None = None
_http: ds_protocol_http_py_lib.utils.http.provider.Http | None = None
__post_init__() None[source]
property type: ds_protocol_http_py_lib.enums.ResourceType

Get the type of the linked service. :returns: ResourceType

property connection: ds_protocol_http_py_lib.utils.http.provider.Http

Get the session. :returns: The session. :rtype: Http

_init_http() ds_protocol_http_py_lib.utils.http.provider.Http[source]

Initialize the Http client instance with HttpConfig and TokenBucket.

Creates an Http instance with: - HttpConfig using headers from the linked service settings - TokenBucket with rate limiting (10 requests per second, capacity of 20)

Subclasses can override this method to customize the entire Http initialization, including custom HttpConfig, TokenBucket, or other Http parameters.

Returns:

The initialized Http client instance.

Return type:

Http

_fetch_user_token(http: ds_protocol_http_py_lib.utils.http.provider.Http) str[source]

Fetch a user token from the token endpoint using the Http provider.

Parameters:

http – The Http instance to use for the request.

Returns:

The user token.

Return type:

str

Raises:
  • LinkedServiceException – If bearer settings are missing.

  • AuthenticationError – If the token is missing in the response.

_fetch_oauth2_token(http: ds_protocol_http_py_lib.utils.http.provider.Http) str[source]

Fetch an OAuth2 token from the token endpoint using the Http provider.

Parameters:

http – The Http instance to use for the request.

Returns:

The OAuth2 token.

Return type:

str

Raises:
  • LinkedServiceException – If OAuth2 settings are missing.

  • AuthenticationError – If the token is missing in the response.

_configure_bearer_auth(http: ds_protocol_http_py_lib.utils.http.provider.Http) None[source]

Configure Bearer authentication.

Fetches a user token via _fetch_user_token and sets the session’s Authorization header.

Parameters:

http – The Http client instance to configure.

_configure_oauth2_auth(http: ds_protocol_http_py_lib.utils.http.provider.Http) None[source]

Configure OAuth2 (client credentials) authentication.

Fetches an OAuth2 token via _fetch_oauth2_token and sets the session’s Authorization header.

Parameters:

http – The Http client instance to configure.

_configure_basic_auth(http: ds_protocol_http_py_lib.utils.http.provider.Http) None[source]

Configure HTTP Basic authentication.

Uses the basic auth settings to construct a base64-encoded username:password token and sets the session’s Authorization header.

Parameters:

http – The Http client instance to configure.

Raises:

LinkedServiceException – If basic auth settings are missing.

_configure_apikey_auth(http: ds_protocol_http_py_lib.utils.http.provider.Http) None[source]

Configure API key authentication.

Updates the session headers with the configured API key name/value.

Parameters:

http – The Http client instance to configure.

Raises:

LinkedServiceException – If API key settings are missing.

_configure_custom_auth(http: ds_protocol_http_py_lib.utils.http.provider.Http) None[source]

Configure custom authentication.

Calls the configured token endpoint and extracts an access token from the JSON response using common token key names. The resulting token is stored in the session Authorization header.

Parameters:

http – The Http client instance to configure.

Raises:
  • AuthenticationError – If the token is missing in the response.

  • LinkedServiceException – If custom auth settings are missing.

_configure_noauth(_http: ds_protocol_http_py_lib.utils.http.provider.Http) None[source]

Configure no authentication.

This is a no-op handler used to keep the auth dispatch table fully typed.

Parameters:

_http – The Http client instance to configure.

connect() None[source]

Connect to the HTTP API and configure authentication.

Initializes the Http client instance if not already initialized. Configures authentication based on the auth_type. Merges configured headers into the session, then applies auth configuration.

Header precedence: - settings.headers are applied first - the selected auth handler may override headers (especially Authorization)

Returns:

The session is configured.

Return type:

None

Raises:
  • AuthenticationError – If the authentication fails.

  • LinkedServiceException – If the auth_type is unsupported.

test_connection() tuple[bool, str][source]

Test the connection to the HTTP API.

Returns:

A tuple containing a boolean indicating success and a string message.

Return type:

tuple[bool, str]

close() None[source]

Close the linked service.

class ds_protocol_http_py_lib.HttpLinkedServiceSettings[source]

Bases: ds_resource_plugin_py_lib.common.resource.linked_service.LinkedServiceSettings

Settings for HTTP linked service connections.

Provide the appropriate auth settings object based on your auth_type:

  • AuthType.API_KEYapi_key

  • AuthType.BASICbasic

  • AuthType.BEARERbearer

  • AuthType.OAUTH2oauth2

  • AuthType.CUSTOMcustom

  • AuthType.NO_AUTH → (no auth settings needed)

Example

>>> settings = HttpLinkedServiceSettings(
...     host="api.example.com",
...     auth_type=AuthType.OAUTH2,
...     oauth2=OAuth2AuthSettings(
...         token_endpoint="https://auth.example.com/token",
...         client_id="my-client",
...         client_secret="secret",
...     ),
... )
host: str

The API host (e.g., ‘api.example.com’).

auth_type: ds_protocol_http_py_lib.enums.AuthType

The authentication type to use.

schema: str = 'https'

URL scheme (‘http’ or ‘https’).

port: int | None = None

Optional port number.

headers: dict[str, str] | None = None

Additional headers to include with all requests.

api_key: ApiKeyAuthSettings | None = None

Settings for API Key authentication. Required when auth_type=AuthType.API_KEY.

basic: BasicAuthSettings | None = None

Settings for Basic authentication. Required when auth_type=AuthType.BASIC.

bearer: BearerAuthSettings | None = None

Settings for Bearer token authentication. Required when auth_type=AuthType.BEARER.

oauth2: OAuth2AuthSettings | None = None

Settings for OAuth2 client credentials authentication. Required when auth_type=AuthType.OAUTH2.

custom: CustomAuthSettings | None = None

Settings for custom token authentication. Required when auth_type=AuthType.CUSTOM.