Skip to main content

Client library for the ComboCurve REST API

Project description

ComboCurve client for Python

Authorization

combocurve_api requires the API key and service account provided by ComboCurve, as shown in the example below:

from combocurve_api_v1 import ServiceAccount, ComboCurveAuth

# Use this to create your service account manually
service_account = ServiceAccount(
    client_email='YOUR_CLIENT_EMAIL',
    client_id='YOUR_CLIENT_ID',
    private_key='YOUR_PRIVATE_KEY',
    private_key_id='YOUR_PRIVATE_KEY_id'
)
# Or use this to load it from a JSON file
# service_account = ServiceAccount.from_file("PATH_TO_JSON_FILE")

# Set your API key
api_key = 'YOUR_API_KEY'

combocurve_auth = ComboCurveAuth(service_account, api_key)

# Get auth headers
auth_headers = combocurve_auth.get_auth_headers()

combocurve_auth.get_auth_headers() should be called before every request so that the token can be refreshed if it's about to expire. After getting the authentication headers, they can be used with any HTTP client library. Below is an example using the Requests library:

import requests

data = [{
    'wellName': 'well 1',
    'dataSource': 'internal',
    'chosenID': '1234'
}, {
    'wellName': 'well 2',
    'dataSource': 'internal',
    'chosenID': '4321'
}]
auth_headers = combocurve_auth.get_auth_headers()
url = 'https://api.combocurve.com/v1/wells'

response = requests.put(url, headers=auth_headers, json=data)
print(response.json())

Content-Type

The ComboCurve API only accepts data serialized as JSON and the Content-Type header must be application/json. Luckily, Requests will take care of both things when the data is passed using the json parameter, as you saw in the example above. Using the data parameter would be less convenient but it works too:

import json

response = requests.put(url,
                        headers={
                            **auth_headers, 'Content-Type': 'application/json'
                        },
                        data=json.dumps(data))

More information here: https://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests

Pagination

When the number of records to be returned for a request is larger than the maximum number of records that can be retrieved in a single response, the requester will need to "paginate", i.e., make multiple requests while there are more records to be returned.

This package provides a helper to assist with that. It parses the response headers and returns a new URL for the next request, if another request is needed. See this example using the Requests library:

from combocurve_api_v1.pagination import get_next_page_url

# See Authorization section
auth_headers = combocurve_auth.get_auth_headers()

# Additional filters are allowed, it is preferred not specify skip if its value is 0
url = 'https://api.combocurve.com/v1/wells?take=200'

# First request
has_more = True

# Keep fetching while there are more records to be returned
while has_more:
    response = requests.get(url, headers=headers)

    # Process response

    url = get_next_page_url(response.headers)
    has_more = url is not None

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

combocurve_api_v1-0.2.7.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

combocurve_api_v1-0.2.7-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file combocurve_api_v1-0.2.7.tar.gz.

File metadata

  • Download URL: combocurve_api_v1-0.2.7.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for combocurve_api_v1-0.2.7.tar.gz
Algorithm Hash digest
SHA256 564eb4b74ff5617d4c31f09ce3317fd79d6feb24f43980ab52436880b2cc6137
MD5 1229593269c9a1cef6f7a8cc69f1620e
BLAKE2b-256 9b49a620525b64674ae0714f579a6de5d0cd280e7cb04ce524ed4509c21cf04e

See more details on using hashes here.

File details

Details for the file combocurve_api_v1-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for combocurve_api_v1-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 99c6fd880837d00ca492bd4dc43c86f917796e3bf8c38904960c3edf478ddada
MD5 a6df8beccd1262d549c9db70e6621b09
BLAKE2b-256 6b12080f2198276f37241641b339a9906b27efa338c612d004467fdbe286144d

See more details on using hashes here.

Supported by

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