Skip to main content

A python client to interact with the ETP server in with a websocket connection

Project description

py-etp-client

License Documentation Status Python CI Python version PyPI Version Status Codecov

An etp client python module to make an etp websocket connexion

installation :

Pip:

pip install py-etp-client

Poetry

poetry add py-etp-client

Usage :

Check example for more information

Interactive client (in example folder):

You can for example run a interactive client with the following code :

Install :

poetry install

Run the client :

poetry run client

Configuration and authentication

You can configure the client with a configuration file (yaml or json) or directly in code. You can also use different authentication methods :

  • Basic authentication (username and password)
  • OAuth2 (client ID and secret)
  • Azure AD (client ID and secret)
  • AWS Cognito (user pool ID and app client ID)
  • GCP OAuth (service account key)
  • Bearer token (pre-fetched token)

It is also possible to create configurations using environment variables.

Server Configuration

These environment variables configure the ETP server connection and behavior:

Environment Variable Description
SERVER__ID Unique identifier for the server configuration
SERVER_NAME Human-readable name for the server configuration
SERVER_URL ETP server URL (including protocol and port)
SERVER_URL_REST ETP server REST API URL (including protocol and port)
SERVER_TIMEOUT Connection timeout in seconds
SERVER_MAX_WEB_SOCKET_FRAME_PAYLOAD_SIZE Maximum WebSocket frame payload size in bytes
SERVER_MAX_WEB_SOCKET_MESSAGE_PAYLOAD_SIZE Maximum WebSocket message payload size in bytes
SERVER_VERIFY_SSL Whether to verify SSL certificates
SERVER_AUTO_RECONNECT Whether to automatically reconnect on connection loss
SERVER_USE_TRANSACTIONS Whether to use ETP transactions
SERVER_SUPPORTED_DATA_OBJECTS List of supported ETP data object types
SERVER_SUPPORTED_PROTOCOLS List of supported ETP protocol versions
SERVER_ADDITIONAL_HEADERS Additional HTTP headers to include in requests
SERVER_ACL_OWNERS OSDU ACL owners list
SERVER_ACL_VIEWERS OSDU ACL viewers list
SERVER_LEGAL_TAGS OSDU legal tags list
SERVER_DATA_COUNTRIES OSDU data countries list
SERVER_AUTH_METHOD Authentication method to use (e.g., basic, oauth2, azure, aws, gcp, bearer)

Basic Authentication

Configure HTTP Basic Authentication credentials:

Environment Variable Description
BASIC_USERNAME Username for basic authentication
BASIC_PASSWORD Password for basic authentication

OAuth2 Authentication

Configure OAuth2 client credentials flow:

Environment Variable Description
OAUTH2_CLIENT_ID OAuth2 client ID
OAUTH2_CLIENT_SECRET OAuth2 client secret
OAUTH2_REFRESH_TOKEN OAuth2 refresh token (optional)
OAUTH2_TOKEN_URL OAuth2 token endpoint URL
OAUTH2_SCOPE OAuth2 scopes (space-separated)

Azure Active Directory Authentication

Configure Azure AD authentication:

Environment Variable Description
AZUREAD_TENANT_ID Azure AD tenant ID
AZUREAD_CLIENT_ID Azure AD application (client) ID
AZUREAD_CLIENT_SECRET Azure AD client secret
AZUREAD_SCOPE Azure AD scopes (space-separated)

AWS Cognito Authentication

Configure AWS Cognito authentication:

Environment Variable Description
AWSCOGNITO_USER_POOL_ID AWS Cognito user pool ID
AWSCOGNITO_APP_CLIENT_ID AWS Cognito app client ID
AWSCOGNITO_CLIENT_SECRET AWS Cognito app client secret
AWSCOGNITO_AWS_REGION AWS region for Cognito
AWSCOGNITO_USERNAME Cognito username
AWSCOGNITO_PASSWORD Cognito password
AWSCOGNITO_REFRESH_TOKEN Cognito refresh token (optional)

Google Cloud Platform Authentication

Configure GCP OAuth2 authentication:

Environment Variable Description
GCPO_GCP_PROJECT_ID GCP project ID
GCPO_SERVICE_ACCOUNT_KEY GCP service account key (JSON string or file path)
GCPO_SCOPE GCP OAuth2 scopes (space-separated)

Bearer Token Authentication

Configure static bearer token authentication:

Environment Variable Description
BEARERTOKEN_CACHED_TOKEN Cached authentication token
BEARERTOKEN_TOKEN_EXPIRES_AT Token expiration time (epoch time)

Usage

Setting Environment Variables

You can set these environment variables in several ways:

  1. System environment variables:

    export SERVER_URL=wss://example.com/etp
    export SERVER_TIMEOUT=60
    
  2. .env file (recommended for development):

    SERVER_URL=wss://example.com/etp
    SERVER_TIMEOUT=60
    AZUREAD_TENANT_ID=your-tenant-id
    AZUREAD_CLIENT_ID=your-client-id
    
  3. Programmatically:

    import os
    os.environ['SERVER_URL'] = 'wss://example.com/etp'
    

Loading from Environment

from py_etp_client.etpconfig import ServerConfig

# Load configuration from environment variables
config = ServerConfig.from_env()

Complex Data Types

For list and dictionary fields, you can provide JSON strings:

export SERVER_SUPPORTED_DATA_OBJECTS='["resqml20.obj_Well", "resqml20.obj_WellboreGeometry"]'
export SERVER_ADDITIONAL_HEADERS='{"data-partition-id": "opendes", "Authorization": "Bearer token"}'

Project details


Download files

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

Source Distribution

py_etp_client-1.1.1.tar.gz (59.1 kB view details)

Uploaded Source

Built Distribution

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

py_etp_client-1.1.1-py3-none-any.whl (63.2 kB view details)

Uploaded Python 3

File details

Details for the file py_etp_client-1.1.1.tar.gz.

File metadata

  • Download URL: py_etp_client-1.1.1.tar.gz
  • Upload date:
  • Size: 59.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for py_etp_client-1.1.1.tar.gz
Algorithm Hash digest
SHA256 7e325c901dfffb6a0e85623e18887d802490a28b51f06fd38e7300c549bfd7d4
MD5 a96ce58ea1035873a94d3e2024ad2eb3
BLAKE2b-256 a863a6180a0c02b26f6bf5179c91749e4ac749840a74ba963cfcb3d7e3f0620b

See more details on using hashes here.

File details

Details for the file py_etp_client-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_etp_client-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 63.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for py_etp_client-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf5a9e518621300d2183f157f22d6bc9f408276a509df599e0d27bd0493e9507
MD5 a6345448ee13e44f8ab983fe5b11cb74
BLAKE2b-256 0f8de2868bd47c2c72306608d1f0f9474b0786700db09e9e522c124bba36356f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page