Skip to main content

This package simplifies the calls to Data Hub's API.

No magic. You need to follow the Data Hub Swagger Documentation for correct formatting of your requests

Be aware that this is a new package, certainly missing many features. Feel free to contribute.

You first need to create an instance of the ApiConnector class with following parameters:

ATTENTION: this package can only be used from Data Hub version 7.0 (July 1, 2025) onward, as it uses the authentication to the the new technology (Keycloak). For previous versions, the opinum-api-connector package must be used (https://github.com/opinum/opinum-api-connector) instead.

VERSION 1.3 Sturdiness and correctness release.

  • The token lifetime now follows the real expiry returned by the authentication server (with a 120 seconds safety margin) instead of a fixed 3 minutes limit, and is renewed with its refresh token when possible.
  • All calls now go through a single persistent connection pool (see the new pool_size parameter) instead of opening a new connection each time, which exhausted the available sockets on long multi-threaded runs.
  • Fixed a retried call sending a doubly encoded body (rejected with a 400), and a token renewed between two attempts not being used. Read timeouts are now retried as well, and the last failed attempt no longer waits before raising.
  • Fixed operation_timeout_sec being ignored on push_data when operation_id was given too, and file names containing special characters on send_file_to_storage.
  • multi_thread_request_on_path now really uses threads (it raised a pickling error before) and splits the calls on max_parameter_entities as documented, instead of on max_futures. Expect different call sizes than in 1.2.
  • ApiConnector can be closed, and used as a context manager, to release its connections.

VERSION 1.2 Fixed operation_id on PUSH calls, and added operation_timeout_sec. Also added the possibility to request a count of items on some calls with the IncludeItemsCount optional parameter.

VERSION 1.1 Improved sturdiness. Added thread lock on token requests, and a default timeout of 10 seconds on all requests (incliding token)

environment

a dictionary of environment variables

if None, ApiConnector uses your environment variables (os.environ)

Mandatory environment variables are:

  • DATAHUB_USERNAME: the Data Hub user.
    TAKE CARE: if this user has access to multiple tenants and if you do not specify a tenant id, ApiConnector will use the last tenant used.
  • DATAHUB_PASSWORD: the password for the user
  • DATAHUB_CLIENT_ID: the client id for accessing the API
  • DATAHUB_CLIENT_SECRET the corresponding secret

Optional environment variables are:

  • DATAHUB_API_URL: another API URL than the Europe SaaS one (https://api.opinum.com)
  • DATAHUB_AUTH_URL: another authentication URL than the Europe SaaS one (https://auth.opinum.com)
  • DATAHUB_PUSH_URL: another push URL than the Europe SaaS one (https://push.opinum.com)
  • DATAHUB_SCOPE: the scope of you session (default: "datahub-api")
    if you want to push data, the scope should be "datahub-api push-data"

account_id

one of the tenant ids available for the Data Hub user (default: None)

retries_when_connection_failure

number of extra attempts when no 200 or 204 return code (default: 0, maximum: 5)

request_timeout

timeout value in seconds on all requests (including fetch token) (default: 10)

log_level

sets log level for the module (default: INFO)

pool_size

size of the connection pool shared by all calls of the instance (default: 32)

it must be at least as large as the number of threads sharing the instance (the workers parameter of multi_thread_request_on_path, default: 16)

Once you have your ApiConnector instance, you may use the class methods

  • get
  • post
  • patch
  • put
  • delete
  • send_file_to_storage

All keyword arguments will be converted to path parameters in the API call with one important exception, the data keyword referring to the body of your call.

There are two other class methods for data pushing because we have another API for this

  • push_data
  • push_dataframe_data

There is a little bit of magic with the method multi_thread_request_on_path that splits a list of parameters Allowing to make parallel calls.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datahub_api_connector-1.3.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datahub_api_connector-1.3-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file datahub_api_connector-1.3.tar.gz.

File metadata

  • Download URL: datahub_api_connector-1.3.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for datahub_api_connector-1.3.tar.gz
Algorithm Hash digest
SHA256 d1a0d29121969c91e02e22a9074ae8601df9168cdc6c32de6fa842972de2f383
MD5 2aac9acebd92dfb4fb55058fd897173c
BLAKE2b-256 b2c50c65c217b7a1efe1feca5c2434da18c9b9f3d057dea826c83dd3e5d731e7

See more details on using hashes here.

File details

Details for the file datahub_api_connector-1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for datahub_api_connector-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ae3b51cd8f9ed60ae0ef4dc58f8a23565580c05bdbe68dab94ca9d8c867faf80
MD5 d599c87e8fbaa35e015fe567846e4dc1
BLAKE2b-256 48d74ea01172fcab385fb2a4687ff975f6416649b7deb5422e00ef2e9fa023d5

See more details on using hashes here.

Release history Release notifications | RSS feed

1.6

2 files

1.5

2 files

1.4

2 files

This release

1.3 This release

2 files

1.2

2 files

1.1

1 file

1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page