Skip to main content

Enverus Direct Access Developer API Python Client

Project description

enverus-developer-api

A thin wrapper around Enverus's Direct Access API. Handles authentication and token management, pagination and network-related error handling/retries.

This module is built and tested on Python 3.6 but should work on Python 2.7 and up.

Install

pip install enverus-developer-api

Usage

Direct Access Version 1

For version 1 of the API, create an instance of the DirectAccessV1 class and provide it your API key

from enverus_developer_api import DirectAccessV1

d1 = DirectAccessV1(api_key='<your-api-key>')

Provide the query method the dataset as the first argument and any query parameters as keyword arguments. See valid dataset names and query params in the Direct Access documentation. The query method returns a generator of API responses as dicts.

for row in d1.query('legal-leases', county_parish='Reeves', state_province='TX', min_expiration_date='2018-06-01'):
    print(row)

Direct Access Version 2

For version 2 of the API, create an instance of the DirectAccessV2 class, providing it your API key, client id and client secret. The returned access token will be available as an attribute on the instance (d2.access_token) and the Authorization header is set automatically

from enverus_developer_api import DirectAccessV2

d2 = DirectAccessV2(
    api_key='<your-api-key>',
    client_id='<your-client-id>',
    client_secret='<your-client-secret>',
)

Like with the V1 class, provide the query method the dataset and query params. All query parameters must match the valid parameters found in the Direct Access documentation and be passed as keyword arguments.

for row in d2.query('well-origins', county='REEVES', pagesize=10000):
    print(row)

Filter functions

Direct Access version 2 supports filter functions. These can be passed as strings on the keyword arguments.

Some common filters are greater than (gt()), less than (lt()), null, not null (not(null)) and between (btw()).
See the Direct Access documentation for a list of all available filters.

# Get well records updated after 2018-08-01 and without deleted dates
for row in d2.query('well-origins', updateddate='gt(2018-08-01)', deleteddate='null'):
    print(row)

# Get permit records with approved dates between 2018-03-01 and 2018-06-01
for row in d2.query('permits', approveddate='btw(2018-03-01,2018-06-01)'):
    print(row) 

You can use the fields keyword to limit the returned fields in your request.

for row in d2.query('rigs', fields='DrillType,LeaseName,PermitDepth'):
    print(row)

Escaping

When making requests containing certain characters like commas, use a backslash to escape them.

# Escaping the comma before LLC
for row in d2.query('producing-entities', curropername='PERCUSSION PETROLEUM OPERATING\, LLC'):
    print(row)

Errors

Direct Access is a data api with hundreds of millions of records depending on your subscription. Networks are inherently unreliable and errors are going to happen at some point. This module provides two means of dealing with errors; configurable retries with exponential backoff (available for v1 and v2), and exposing the pagination link as an attribute (v2 only).

Retrying while making requests

from enverus_developer_api import DirectAccessV1

# Retry 5 times, backing off exponentially 
# (1 second, 2 seconds, 4 seconds, 16 seconds, 256 seconds)
d1 = DirectAccessV1(
    api_key='<your-api-key>',
    retries=5,
    backoff_factor=1
)

In the event of an unrecoverable error, you can write your process in a way that persists the pagination links so that you can pick back up where you left off. A basic implementation might look like this:

import os
import json
from enverus_developer_api import DirectAccessV2

RECOVERY_FILE = 'your-api-links.json'

d2 = DirectAccessV2(
    api_key='<your-api-key>',
    client_id='<your-client-id>',
    client_secret='<your-client-secret>',
    retries=5,
    backoff_factor=1    
)

# if there's an existing recovery file, provide it to the instance
if os.path.exists(RECOVERY_FILE):
    with open(RECOVERY_FILE) as f:
        d2.links = json.loads(f.read())

# interact with the api, writing out a recovery file in the event of an unrecoverable error. 
# this will overwrite any previously existing file.
try:
    for row in d2.query('permits'):
        print(row)
except Exception:
    with open(RECOVERY_FILE, mode='w') as f:
        f.write(json.dumps(d2.links))

You could persist the pagination links any way you want. If provided, the DirectAccessV2 class expects a dictionary like the one provided from the Requests module's links and the json example above is just one way to do this.

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

enverus-developer-api-1.4.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

enverus_developer_api-1.4.0-py2.py3-none-any.whl (11.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file enverus-developer-api-1.4.0.tar.gz.

File metadata

  • Download URL: enverus-developer-api-1.4.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for enverus-developer-api-1.4.0.tar.gz
Algorithm Hash digest
SHA256 b72bdda9bfac8d0c0a5c5ae4f003989d58793ff8cd14215fc8ecd66c85bc3a3f
MD5 12206e6579486f4bd9c977f67f57de2a
BLAKE2b-256 672d90b21f786edb4119fc7e063c8e200d8693b1ff7c5e375ed9b91c51a22aa2

See more details on using hashes here.

File details

Details for the file enverus_developer_api-1.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: enverus_developer_api-1.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for enverus_developer_api-1.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 abf91caa19e8e0a6bb2bc5a7ffe0b2a1f3548da9694a7e84a1e90064ff736de5
MD5 694a468719cd1904dda99fabf0c573c0
BLAKE2b-256 d489418db2fa2e956ffb478cf7be92a3dc766e4d2611a567522d8639b2bfc57e

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