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.6.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distribution

combocurve_api_v1-0.2.6-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

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