Skip to main content

Whitson Python SDK for developers, data scientists, and engineers working with Whitson+

Project description

Whitson Python SDK

release GitHub PyPI version

This is the Whitson Python SDK for developers, data scientists, and engineers working with Whitson+.

The API documentation is accessible with the client name: https://<CLIENT_NAME>.whitson.com/api-external/swagger/

The source code is located in the whitson/client directory.

Example usage

Store your secrets in a .env file:

WHITSON_CLIENT_NAME=<client-name>
WHITSON_CLIENT_ID=<client-id>
WHITSON_CLIENT_SECRET=<client-secret>
PATH_TO_TOKEN=token.json

If you have it, store your token in a JSON file. If not, it will be automatically generated and saved in the directory specified by PATH_TO_TOKEN:

 {
   'access_token': '<access-token-value>',
   'scope': 'get:api post:api delete:api',
   'expires_in': 86400,
   'token_type': 'Bearer',
   'issued_at': 1692136969.7024412
 }

In a Python file:

from decouple import config

from whitson.client import WhitsonClient
from whitson.client.config import ClientConfig

# Get environment variables
client_name = config("WHITSON_CLIENT_NAME")
client_id = config("WHITSON_CLIENT_ID")
client_secret = config("WHITSON_CLIENT_SECRET")
path_to_token = config("WHITSON_TOKEN_PATH")

# CONNECT TO WHITSON
# If no token_path is specified, the default location ("token.json") will be used.
# If certain certificates are required for data to be requested, this can be specified in a PEM file
config = ClientConfig(
    client_name=client_name,
    client_id=client_id,
    client_secret=client_secret,
    pem_path="src/custom_cacerts.pem",  # optional, may be required to traverse firewall
    token_path=path_to_token  # where the token will be saved
)

# Instantiate client and retrieve data
client = WhitsonClient(config)

# Constants
FIELD_ID = 1
PROJECT_ID = 159

# Get field
field = client.fields.retrieve(field_id=FIELD_ID)
print(f"{field.name} field retrieved.")

# Get project associated with field
project = client.projects.retrieve(field_id=field.id, project_id=PROJECT_ID)
print(f"{project.name} project retrieved.")

# Get wells associated to the project
wells = client.wells.list(project_id=project.id)
well = wells[0]
print(f"{well.name} retrieved.")

# Run BHP calculations for a well
client.wells.run_bhp_calc(well_id=well.id)
print("BHP calculations complete.")

# Retrieve BHP calculations for a well
bhp_corr_well = client.wells.retrieve_bhp_calcs(well_id=well.id)
print(f"BHP calculations retrieved for {well.name} ({well.id}).")

# Retrieve all BHP calculations in a project
bhp_corr = client.wells.retrieve_bhp_calcs(project_id=project.id)
print("BHP calculations retrieved for all wells.")

Improvements

  • The list() and retrieve() functions in the api/ classes are very similiar. Need to find a way to simplify this.
  • Tests need to be written to show expected result when retrieving data

Acknowledgements

I learned a great deal from the amazing and talented people at Cognite and this repository is heavily based off of the structure of the publicly available Cognite Python SDK. Thank you for the incredible experience and the continued learning your resources have provided me.

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

whitson_sdk_python-0.4.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

whitson_sdk_python-0.4.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file whitson_sdk_python-0.4.0.tar.gz.

File metadata

  • Download URL: whitson_sdk_python-0.4.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for whitson_sdk_python-0.4.0.tar.gz
Algorithm Hash digest
SHA256 840cdcbb9c78f01aee30c2da225af80f4c017772dc2e412223d95e6686d600a0
MD5 2cf4f3f3e167b3dfeb7456ea13c7346c
BLAKE2b-256 d2a9021fa1fb67431a228bec51f37d8db2c159262089ed607ba41997965631ba

See more details on using hashes here.

File details

Details for the file whitson_sdk_python-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for whitson_sdk_python-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9e85074b4d83b1e9a7d85f0921eeb90d8f5b403e2aedae3ed3d2af86d433e7b
MD5 5a30dc23f85cbded1bcd8fe98280f229
BLAKE2b-256 8035b7f0e4f87bc830c41dea130a54fdb6079ed151e7ba6850aa78a75c9f08f5

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