### Install direct-access-py manually from source Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Installs the direct-access-py library by cloning the repository from GitHub and running the setup script. This method allows for manual installation or development. ```bash git clone https://github.com/wchatx/direct-access-py.git cd directaccess/ python setup.py install ``` -------------------------------- ### Install direct-access-py using pip Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Installs the direct-access-py library from the Python Package Index using pip. This is the recommended and simplest installation method. ```bash pip install directaccess ``` -------------------------------- ### Direct Access Version 2 Query Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Example of how to query data using the Direct Access Version 2 API, including common parameters and concepts. ```APIDOC ## Direct Access Version 2 Query ### Description Queries data using the Direct Access Version 2 API. This is the current version and supports advanced features like filter functions and field selection. ### Method POST (Implicitly through the library) ### Endpoint Not directly exposed, handled by the `directaccess` library. ### Parameters #### Path Parameters None #### Query Parameters - **dataset** (string) - Required - The name of the dataset to query. - **keyword arguments** (various) - Optional - Query parameters specific to the dataset, as defined in the Direct Access documentation. This can include filter functions (e.g., `gt()`, `lt()`, `btw()`, `null`), `deleteddate='null'`, `fields`, and other standard query parameters. ### Request Example ```python from directaccess import DirectAccessV2 d2 = DirectAccessV2( api_key='your-api-key', client_id='your-client-id', client_secret='your-client-secret', ) # Basic query for row in d2.query('well-origins', county='REEVES', pagesize=10000): print(row) # Query with filter functions for row in d2.query('well-origins', updateddate='gt(2018-08-01)', deleteddate='null'): print(row) # Query with date range filter for row in d2.query('permits', approveddate='btw(2018-03-01,2018-06-01)'): print(row) # Query with specific fields for row in d2.query('rigs', fields='DrillType,LeaseName,PermitDepth'): print(row) # Query with escaping characters for row in d2.query('producing-entities', curropername='PERCUSSION PETROLEUM OPERATING\, LLC'): print(row) ``` ### Response #### Success Response (200) - **generator of dictionaries** - Each dictionary represents a row of data returned by the API, potentially limited by the `fields` parameter. #### Response Example ```json { "example": "{\"well_id\": \"some_well_id\", \"county\": \"REEVES\", \"updateddate\": \"2018-08-02T10:00:00Z\"}" } ``` ``` -------------------------------- ### Install Pandas for to_dataframe Function Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Provides the command to install the pandas library, which is a prerequisite for using the 'to_dataframe' function to convert API query results into pandas DataFrames. ```bash pip install pandas ``` -------------------------------- ### Direct Access - Version 2 Client Setup Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Instantiate the DirectAccessV2 client with your API key, client ID, and client secret. The access token is managed automatically. ```APIDOC ## Direct Access - Version 2 Client Setup ### Description To use the Direct Access Version 2 API, instantiate the `DirectAccessV2` class with your API key, client ID, and client secret. The client manages authentication and token refresh. ### Method Instantiate class ### Endpoint N/A (Client-side instantiation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **client_id** (string) - Required - Your Enverus client ID. * **client_secret** (string) - Required - Your Enverus client secret. * **api_key** (string) - Required - Your Enverus API key. ### Request Example ```python from enverus_developer_api import DirectAccessV2 d2 = DirectAccessV2( client_id='', client_secret='', api_key='' ) ``` ### Response #### Success Response (200) Client instance created successfully. The `access_token` attribute will hold the generated token. #### Response Example ```json { "message": "Client initialized successfully", "access_token": "" } ``` ``` -------------------------------- ### GET /docs Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Retrieves a sample response for a given dataset, useful for understanding data structure and content. ```APIDOC ## GET /docs ### Description Returns a sample response for a specified dataset, providing insight into its structure and typical data. ### Method GET ### Endpoint `/docs` ### Parameters #### Path Parameters N/A #### Query Parameters - **dataset** (string) - Required - The name of the dataset to retrieve documentation for. #### Request Body N/A ### Request Example ```python docs = v3.docs("casings") ``` ### Response #### Success Response (200) A sample JSON response representing the structure and data of the requested dataset. #### Response Example ```json { "example": "sample response data" } ``` ``` -------------------------------- ### Developer API - Version 3 Client Setup Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Instantiate the DeveloperAPIv3 client with your secret key. The access token is automatically managed and available as an attribute. ```APIDOC ## Developer API - Version 3 Client Setup ### Description To use the Developer API Version 3, instantiate the `DeveloperAPIv3` class with your secret key. The client handles authentication and token management automatically. ### Method Instantiate class ### Endpoint N/A (Client-side instantiation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **secret_key** (string) - Required - Your Enverus secret key. ### Request Example ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3(secret_key='') ``` ### Response #### Success Response (200) Client instance created successfully. The `access_token` attribute will hold the generated token. #### Response Example ```json { "message": "Client initialized successfully", "access_token": "" } ``` ``` -------------------------------- ### Get Dataset Documentation Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Fetches sample response data for a given dataset, providing insight into its structure and available fields. ```APIDOC ## Get Dataset Documentation ### Description Retrieve sample response data for a dataset to understand the structure and available fields. ### Method GET (Implicit via `v3.docs`) ### Endpoint N/A (Client-side operation) ### Parameters #### Query Parameters - **dataset** (string) - Required - The name of the dataset for which to retrieve documentation. ### Request Example ```python from enverus_developer_api import DeveloperAPIv3 import json v3 = DeveloperAPIv3(secret_key='your-secret-key') # Get sample docs for dataset docs = v3.docs('casings') print(json.dumps(docs, indent=2)) # Get docs for wells docs = v3.docs('wells') if docs: # Print available fields print('Available fields:', list(docs[0].keys())) ``` ### Response - **docs** (list of dicts) - A list containing sample records from the dataset, or an empty list if the dataset is not found or has no data. ``` -------------------------------- ### Direct Access Version 1 Query Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Example of how to query data using the Direct Access Version 1 API. This version will be deprecated. ```APIDOC ## Direct Access Version 1 Query ### Description Queries data using the Direct Access Version 1 API. This version is set to reach end-of-life in July 2020. ### Method POST (Implicitly through the library) ### Endpoint Not directly exposed, handled by the `directaccess` library. ### Parameters #### Path Parameters None #### Query Parameters - **dataset** (string) - Required - The name of the dataset to query. - **keyword arguments** (various) - Optional - Query parameters specific to the dataset, as defined in the Direct Access documentation. ### Request Example ```python from directaccess import DirectAccessV1 d1 = DirectAccessV1(api_key='your-api-key') for row in d1.query('legal-leases', county_parish='Reeves', state_province='TX'): print(row) ``` ### Response #### Success Response (200) - **generator of dictionaries** - Each dictionary represents a row of data returned by the API. #### Response Example ```json { "example": "{\"lease_id\": \"some_id\", \"county_parish\": \"Reeves\", \"state_province\": \"TX\"}" } ``` ``` -------------------------------- ### Install enverus-developer-api Package Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md This command installs the enverus-developer-api package using pip. Ensure you have Python and pip installed on your system. ```command-line pip install enverus-developer-api ``` -------------------------------- ### Direct Access API - Rig Data Retrieval and Processing Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb This section demonstrates how to initialize the Direct Access API client, query for rig data in a specific state, write the data to a CSV file, and then load it into a Pandas DataFrame. ```APIDOC ## Direct Access API - Rig Data Retrieval and Processing ### Description This section demonstrates how to initialize the Direct Access API client, query for rig data in a specific state, write the data to a CSV file, and then load it into a Pandas DataFrame. ### Method GET (Implicit through `d2.query`) ### Endpoint `/rigs` (within the Direct Access API) ### Parameters #### Query Parameters - **distateprovincename** (string) - Required - The name of the state or province to query rigs for (e.g., 'TEXAS'). ### Request Body None ### Request Example ```python # Initialize the Direct Access API client import os from directaccess import DirectAccessV2 DIRECTACCESS_CLIENT_ID = os.getenv('DIRECTACCESS_CLIENT_ID') DIRECTACCESS_CLIENT_SECRET = os.getenv('DIRECTACCESS_CLIENT_SECRET') d2 = DirectAccessV2( client_id=DIRECTACCESS_CLIENT_ID, client_secret=DIRECTACCESS_CLIENT_SECRET, log_level=logging.WARNING ) # Query for rigs in Texas and write to CSV import csv import pandas as pd csv_file = 'TEXAS.csv' query = d2.query('rigs', distateprovincename=csv_file[:-4]) with open(csv_file, mode='w') as f: writer = csv.writer(f) for i, row in enumerate(query, start=1): if i == 1: writer.writerow(row.keys()) writer.writerow(row.values()) df = pd.read_csv(csv_file) os.remove(csv_file) ``` ### Response #### Success Response (200) - **DataFrame** (pandas.DataFrame) - A Pandas DataFrame containing the rig data retrieved from the API. #### Response Example (DataFrame content will vary based on query results) ``` -------------------------------- ### Initialize DirectAccessV1 Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Creates an instance of the DirectAccessV1 class, which is used to interact with version 1 of the Enverus Developer API. Requires an API key for authentication. ```python from directaccess import DirectAccessV1 d1 = DirectAccessV1(api_key='your-api-key') ``` -------------------------------- ### Initialize DirectAccessV2 Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Creates an instance of the DirectAccessV2 class for interacting with version 2 of the Enverus Developer API. Requires API key, client ID, and client secret for authentication. The access token is automatically managed. ```python from directaccess import DirectAccessV2 d2 = DirectAccessV2( api_key='your-api-key', client_id='your-client-id', client_secret='your-client-secret', ) ``` -------------------------------- ### Get Sample Response for Dataset (docs) Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Retrieves a sample response for a specified dataset using the 'docs' function. This function is useful for understanding the structure and content of the data available for a particular dataset. ```python docs = v3.docs("casings") ``` -------------------------------- ### Set Direct Access Credentials using Environment Variables Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb This snippet shows how to set up your Direct Access API credentials by retrieving your client ID and client secret from environment variables. This is a common practice for securely managing sensitive information. ```python # Set our Direct Access credentials. In this case, we're using environment variables to hide our credentials. import os DIRECTACCESS_CLIENT_ID = os.getenv('DIRECTACCESS_CLIENT_ID') DIRECTACCESS_CLIENT_SECRET = os.getenv('DIRECTACCESS_CLIENT_SECRET') ``` -------------------------------- ### GET /query Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Queries a dataset with specified options, returning records as dictionaries. Supports pagination and custom headers. ```APIDOC ## GET /query ### Description Queries a specified dataset with optional parameters and returns records as dictionaries. This method supports pagination and allows for custom request headers. ### Method GET ### Endpoint `/query` ### Parameters #### Path Parameters N/A #### Query Parameters - **dataset** (string) - Required - The name of the dataset to query. - **pagesize** (integer) - Optional - The number of records to return per page. - **deleteddate** (string) - Optional - Filter criteria, e.g., 'null' to exclude deleted records. - **_headers** (dict) - Optional - A dictionary of custom request headers, e.g., `{'X-Omit-Header-Next-Links': 'true'}`. #### Request Body N/A (Parameters are passed as query arguments) ### Request Example ```python for row in v3.query("rigs", pagesize=1000, deleteddate="null"): print(row) # Example with custom header to omit next links for row in v3.query("rigs", pagesize=1000, deleteddate="null", _headers={'X-Omit-Header-Next-Links': 'true'}): print(row) ``` ### Response #### Success Response (200) An iterable of dictionaries, where each dictionary represents a record from the dataset. #### Response Example ```json [ { "field1": "value1", "field2": "value2" }, { "field1": "value3", "field2": "value4" } ] ``` ``` -------------------------------- ### Initialize Direct Access API Client Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb Initializes the Direct Access API client object (`DirectAccessV2`). It takes the client ID and client secret as arguments. Optionally, a logging level can be set to control the verbosity of the API client's output. ```python # Initialize our api client object. Optionally, we can pass a logging level to avoid cluttering our notebook import logging from directaccess import DirectAccessV2 d2 = DirectAccessV2( client_id=DIRECTACCESS_CLIENT_ID, client_secret=DIRECTACCESS_CLIENT_SECRET, log_level=logging.WARNING ) ``` -------------------------------- ### GET /ddl Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Generates a CREATE TABLE DDL statement for a given dataset, supporting both MS SQL Server and PostgreSQL formats. ```APIDOC ## GET /ddl ### Description Generates a `CREATE TABLE` DDL statement for a specified dataset, compatible with MS SQL Server (`mssql`) or PostgreSQL (`pg`). ### Method GET ### Endpoint `/ddl` ### Parameters #### Path Parameters N/A #### Query Parameters - **dataset** (string) - Required - The name of the dataset for which to generate the DDL. - **database** (string) - Required - The target database system (`mssql` or `pg`). #### Request Body N/A ### Request Example ```python from tempfile import TemporaryFile ddl = v3.ddl("casings", database="pg") with TemporaryFile(mode="w+") as f: f.write(ddl) f.seek(0) for line in f: print(line, end='') ``` ### Response #### Success Response (200) A string containing the `CREATE TABLE` DDL statement for the specified dataset and database. #### Response Example ```sql -- Example DDL for PostgreSQL CREATE TABLE casings ( -- columns definitions here... ); ``` ``` -------------------------------- ### GeoDataFrame Creation and Map Visualization Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb This section explains how to convert the Pandas DataFrame into a GeoDataFrame, which allows for geospatial analysis and plotting. It then demonstrates creating a basic plot and a more detailed plot with a basemap. ```APIDOC ## GeoDataFrame Creation and Map Visualization ### Description This section explains how to convert the Pandas DataFrame into a GeoDataFrame, which allows for geospatial analysis and plotting. It then demonstrates creating a basic plot and a more detailed plot with a basemap. ### Method N/A (Data transformation and plotting) ### Endpoint N/A ### Parameters #### Request Body None ### Request Example ```python # Import necessary libraries from geopandas import GeoDataFrame from shapely.geometry import Point import contextily as ctx import matplotlib.pyplot as plt # Assuming 'df' is the Pandas DataFrame from the previous step # Turn Latitude and Longitude into Shapely Point geometry geometry = [Point(xy) for xy in zip(df.RigLongitudeWGS84, df.RigLatitudeWGS84)] # Drop original Lat/Lon columns (optional) df = df.drop(['RigLongitudeWGS84', 'RigLatitudeWGS84'], axis=1) # Set the Coordinate Reference System (EPSG:4326 for WGS84) crs = {'init': 'epsg:4326'} # Create the GeoDataFrame gdf = GeoDataFrame(df, crs=crs, geometry=geometry) # Convert to Web Mercator for basemap compatibility gdf = gdf.to_crs(epsg=3857) # Helper function to add a basemap def add_basemap(ax, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png'): xmin, xmax, ymin, ymax = ax.axis() basemap, extent = ctx.bounds2img(xmin, ymin, xmax, ymax, zoom=zoom, url=url) ax.imshow(basemap, extent=extent, interpolation='bilinear') ax.axis((xmin, xmax, ymin, ymax)) # Plotting the data fig, ax = plt.subplots(figsize=(10, 10)) gdf.plot(ax=ax, alpha=0.5, edgecolor='k') add_basemap(ax, zoom=10) plt.show() ``` ### Response #### Success Response (200) - **Plot** (matplotlib.figure.Figure) - A plot displaying the rig data on a map with a terrain basemap. #### Response Example (Visual map output) ``` -------------------------------- ### Get Dataset Documentation with Enverus API Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Retrieves sample response data for a specified dataset, providing insights into its structure and available fields. The documentation is returned as a list of dictionaries, which can be easily inspected or processed. ```python from enverus_developer_api import DeveloperAPIv3 import json v3 = DeveloperAPIv3(secret_key='your-secret-key') # Get sample docs for dataset docs = v3.docs('casings') print(json.dumps(docs, indent=2)) # Get docs for wells docs = v3.docs('wells') if docs: # Print available fields print('Available fields:', list(docs[0].keys())) ``` -------------------------------- ### Create DataFrame with Data Converters (to_dataframe) Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Demonstrates creating a pandas DataFrame from a dataset query, applying custom data converters to modify specific columns. This example replaces state abbreviations with full names and removes commas from operator names. ```python df = v3.to_dataframe( dataset="rigs", deleteddate="null", pagesize=100000, stateprovince="TX", converters={ "StateProvince": lambda x: "TEXAS", "ENVOperator": lambda x: x.replace(",", "") } ) df.head(10) ``` -------------------------------- ### Plot GeoDataFrame Points Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb Generates a basic plot of the rig points from the GeoDataFrame. This provides a simple visualization of the spatial distribution of the rigs. ```python # Show our points on a basic plot ax = gdf.plot(figsize=(10, 10), alpha=0.5, edgecolor='k') ``` -------------------------------- ### Plot GeoDataFrame with Terrain Basemap Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb Visualizes the rig data on a plot that includes a terrain basemap using the `add_basemap` helper function. This provides a more geographically informative map of the rig locations. ```python # Show our results on another plot with a terrain basemap (running this cell might take a moment...) ax = gdf.plot(figsize=(10, 10), alpha=0.5, edgecolor='k') add_basemap(ax, zoom=10) ``` -------------------------------- ### Query API, Write to CSV, and Create Pandas DataFrame Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb This snippet demonstrates querying the Direct Access API for rigs in Texas, writing the results to a CSV file, and then reading that CSV into a Pandas DataFrame. The temporary CSV file is removed after the DataFrame is created. ```python import csv import pandas as pd csv_file = 'TEXAS.csv' query = d2.query('rigs', distateprovincename=csv_file[:-4]) # Rigs in TEXAS with open(csv_file, mode='w') as f: writer = csv.writer(f) for i, row in enumerate(query, start=1): if i == 1: writer.writerow(row.keys()) writer.writerow(row.values()) df = pd.read_csv(csv_file) os.remove(csv_file) ``` -------------------------------- ### Convert GeoDataFrame to Web Mercator Projection Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb Transforms the GeoDataFrame from its current Coordinate Reference System (likely WGS84) to the Web Mercator projection (EPSG:3857). This is often required for displaying data on web-based maps. ```python # Convert to Web Mercator gdf = gdf.to_crs(epsg=3857) ``` -------------------------------- ### Query data using DirectAccessV2 Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Executes a query against the Direct Access API Version 2. Similar to V1, it uses the `query` method with a dataset and keyword arguments. The `pagesize` parameter can be used to control the number of results per request. ```python for row in d2.query('well-origins', county='REEVES', pagesize=10000): print(row) ``` -------------------------------- ### Limit returned fields using 'fields' keyword in DirectAccessV2 Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Shows how to use the `fields` keyword argument in Direct Access V2 queries to specify which columns to retrieve. This optimizes query performance by reducing the amount of data transferred. ```python for row in d2.query('rigs', fields='DrillType,LeaseName,PermitDepth'): print(row) ``` -------------------------------- ### Query data using DirectAccessV1 Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Performs a query against the Direct Access API Version 1. The `query` method takes a dataset name and optional keyword arguments for filtering. It returns a generator of response dictionaries. ```python for row in d1.query('legal-leases', county_parish='Reeves', state_province='TX'): print(row) ``` -------------------------------- ### Get CREATE TABLE DDL Statement (ddl) Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Generates a CREATE TABLE DDL statement for a given dataset, supporting both MS SQL Server ('mssql') and PostgreSQL ('pg') formats. The output can be written to a file for database schema creation. ```python from tempfile import TemporaryFile ddl = v3.ddl("casings", database="pg") with TemporaryFile(mode="w+") as f: f.write(ddl) f.seek(0) for line in f: print(line, end='') ``` -------------------------------- ### Configure Network Retry Behavior (Python) Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt This snippet illustrates how to configure network retry behavior, including retry attempts, backoff timing, and SSL verification for the DeveloperAPIv3 client. It shows examples for setting retries, proxies, disabling SSL verification, and combined configurations. ```Python from enverus_developer_api import DeveloperAPIv3 # Configure retries and backoff v3 = DeveloperAPIv3( secret_key='your-secret-key', retries=5, backoff_factor=1 ) # Configure proxy v3 = DeveloperAPIv3( secret_key='your-secret-key', proxies={'https': 'http://10.10.1.10:1080'} ) # Disable SSL verification (not recommended) v3 = DeveloperAPIv3( secret_key='your-secret-key', verify=False ) # Combined configuration v3 = DeveloperAPIv3( secret_key='your-secret-key', retries=10, backoff_factor=2, proxies={'https': 'http://proxy.example.com:8080'}, verify=True ) # Query with configured client for row in v3.query('rigs', deleteddate='null', pagesize=5000): print(row) ``` -------------------------------- ### Query with filter functions in DirectAccessV2 Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Demonstrates using filter functions like 'gt()' (greater than) and 'null' with the `query` method in Direct Access V2. This allows for more precise data retrieval based on date ranges or null values. ```python # 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) ``` -------------------------------- ### Create GeoDataFrame from Pandas DataFrame Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb Converts a Pandas DataFrame containing rig data (with latitude and longitude columns) into a GeoDataFrame. It creates Shapely Point geometries from the coordinates and sets the Coordinate Reference System (CRS) to EPSG 4326 (WGS84). ```python # Import the GeoDataFrame and Point classes. from geopandas import GeoDataFrame from shapely.geometry import Point # Turn our Latitude and Longitude fields into a Shapely Point geometry geometry = [Point(xy) for xy in zip(df.RigLongitudeWGS84, df.RigLatitudeWGS84)] # Drop the Latitude and Longitude columns, though this isn't necessary df = df.drop(['RigLongitudeWGS84', 'RigLatitudeWGS84'], axis=1) # Set the Coordinate Reference System, which is EPSG 4326 (WGS84) crs = {'init': 'epsg:4326'} # Finally, create our GeoDataFrame, passing the Pandas DataFrame, the CRS and the geometry object gdf = GeoDataFrame(df, crs=crs, geometry=geometry) ``` -------------------------------- ### GET /count Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Retrieves the count of records for a given dataset, with results available in the `X-QUERY-RECORD-COUNT` response header. ```APIDOC ## GET /count ### Description Returns the total count of records for a specified dataset. The count is provided in the `X-QUERY-RECORD-COUNT` response header. ### Method GET ### Endpoint `/count` ### Parameters #### Path Parameters N/A #### Query Parameters - **dataset** (string) - Required - The name of the dataset to count records from. - **deleteddate** (string) - Optional - Filter criteria, e.g., 'null' to exclude deleted records. #### Request Body N/A ### Request Example ```python count = v3.count("rigs", deleteddate="null") ``` ### Response #### Success Response (200) An empty response body. The record count is available in the `X-QUERY-RECORD-COUNT` header. #### Response Example ``` X-QUERY-RECORD-COUNT: 12345 ``` ``` -------------------------------- ### Initialize DirectAccessV2 Client Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Instantiate the DirectAccessV2 client for API v2. Requires client_id and client_secret. Can also initialize with an existing access token, which is useful for multiprocessing. ```python from enverus_developer_api import DirectAccessV2 # Basic initialization d2 = DirectAccessV2( client_id='your-client-id', client_secret='your-client-secret' ) # With existing access token (useful for multiprocessing) d2 = DirectAccessV2( client_id='your-client-id', client_secret='your-client-secret', access_token='existing-token', retries=5, backoff_factor=1 ) ``` -------------------------------- ### Get DDL Schema Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Retrieves the Data Definition Language (DDL) for a specified dataset, supporting both Microsoft SQL Server and PostgreSQL syntax. ```APIDOC ## Get DDL Schema ### Description Retrieve CREATE TABLE DDL statements for any dataset, supporting both Microsoft SQL Server and PostgreSQL syntax. ### Method GET (Implicit via `v3.ddl`) ### Endpoint N/A (Client-side operation) ### Parameters #### Query Parameters - **dataset** (string) - Required - The name of the dataset for which to retrieve the DDL. - **database** (string) - Optional - The target database syntax ('pg' for PostgreSQL, 'mssql' for Microsoft SQL Server). Defaults to 'pg'. ### Request Example ```python from tempfile import TemporaryFile from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3(secret_key='your-secret-key') # Get PostgreSQL DDL ddl = v3.ddl('casings', database='pg') print(ddl) # Get Microsoft SQL Server DDL ddl = v3.ddl('wells', database='mssql') # Write DDL to file with TemporaryFile(mode='w+') as f: f.write(ddl) f.seek(0) for line in f: print(line, end='') ``` ### Response - **ddl** (string) - The SQL DDL statement for the specified dataset. ``` -------------------------------- ### Initialize DeveloperAPIv3 Client Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Instantiate the DeveloperAPIv3 client for API v3. Handles authentication and token management automatically. Supports network configuration like retries, backoff, proxies, and SSL verification. ```python from enverus_developer_api import DeveloperAPIv3 # Basic initialization v3 = DeveloperAPIv3(secret_key='your-secret-key-here') # With network configuration v3 = DeveloperAPIv3( secret_key='your-secret-key-here', retries=5, backoff_factor=1, proxies={'https': 'http://10.10.1.10:1080'}, verify=True ) # Access token is automatically retrieved and available print(v3.access_token) ``` -------------------------------- ### DeveloperAPIv3 Initialization with Network Proxy Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Initialize the DeveloperAPIv3 client with network proxy settings to route requests through a specified proxy server. ```APIDOC ## DeveloperAPIv3 Initialization with Network Proxy ### Description Initializes the `DeveloperAPIv3` client, enabling the configuration of network proxies for routing API requests. ### Method Instantiation of the `DeveloperAPIv3` class. ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3( secret_key='', proxies={'https': 'http://10.10.1.10:1080'} ) ``` ### Response #### Success Response (200) N/A (Client initialization) #### Response Example N/A ``` -------------------------------- ### Get Record Count for Dataset (count) Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Fetches the count of records for a specified dataset. This function allows filtering based on query options, such as 'deleteddate', and returns the count in the 'X-QUERY-RECORD-COUNT' response header. ```python count = v3.count("rigs", deleteddate="null") ``` -------------------------------- ### Export to CSV Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Demonstrates how to query data from a dataset and export it to a CSV file, with options for specifying the delimiter and logging progress. Also shows how to read the created CSV file. ```APIDOC ## Export to CSV ### Description Demonstrates how to query data from a dataset and export it to a CSV file, with options for specifying the delimiter and logging progress. Also shows how to read the created CSV file. ### Method POST (Implicit via `v3.query` and `v3.to_csv`) ### Endpoint N/A (Client-side operation) ### Parameters #### Query Parameters (for `v3.query`) - **dataset** (string) - Required - The name of the dataset to query. - **pagesize** (integer) - Optional - The number of records to retrieve per page. - **deleteddate** (string) - Optional - Filter for deleted records (e.g., 'null'). - **stateprovince** (string) - Optional - Filter by state or province. - **county** (string) - Optional - Filter by county. #### Request Body (for `v3.to_csv`) - **query_iterator** - The iterator returned by `v3.query`. - **path** (string) - Required - The file path to save the CSV. - **log_progress** (boolean) - Optional - Whether to log progress during writing. - **delimiter** (string) - Optional - The delimiter for the CSV file (default is comma). - **quoting** (integer) - Optional - CSV quoting behavior. ### Request Example ```python from enverus_developer_api import DeveloperAPIv3 import csv v3 = DeveloperAPIv3(secret_key='your-secret-key') # Define query dataset = 'rigs' options = dict(pagesize=10000, deleteddate='null', stateprovince='TX') # Create query iterator query = v3.query(dataset, **options) # Write to CSV with progress logging path = '/path/to/output.csv' v3.to_csv(query, path, log_progress=True, delimiter=',', quoting=csv.QUOTE_MINIMAL) # Read the CSV with open(path, mode='r') as f: reader = csv.reader(f) for row in reader: print(row) break # Just show header ``` ### Response N/A (This operation writes to a file). ``` -------------------------------- ### Initialize DeveloperAPIv3 with Network Proxy Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Initializes the DeveloperAPIv3 client, configuring it to use a network proxy. This is essential when operating in environments that require traffic to be routed through a proxy server. The 'proxies' argument takes a dictionary specifying the proxy host and port. ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3( secret_key='', proxies={'https': 'http://10.10.1.10:1080'} ) ``` -------------------------------- ### Instantiate DirectAccessV2 Client Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Create an instance of the DirectAccessV2 class to interact with version 2 of the Enverus Direct Access API. Requires client_id and client_secret. The access token is automatically managed. ```python from enverus_developer_api import DirectAccessV2 d2 = DirectAccessV2( client_id='', client_secret='', ) ``` -------------------------------- ### DeveloperAPIv3 Initialization with Retries and Backoff Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Initialize the DeveloperAPIv3 client with custom retry attempts and backoff factor for handling transient network issues. ```APIDOC ## DeveloperAPIv3 Initialization with Retries and Backoff ### Description Initializes the `DeveloperAPIv3` client, allowing configuration of retry attempts and backoff factor to manage network request retries. ### Method Instantiation of the `DeveloperAPIv3` class. ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3( secret_key='', retries=5, backoff_factor=1 ) ``` ### Response #### Success Response (200) N/A (Client initialization) #### Response Example N/A ``` -------------------------------- ### Escape special characters in DirectAccessV2 queries Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/docs/usage.md Illustrates how to escape special characters, such as commas, within query parameters when using Direct Access V2. A backslash `\` is used to escape these characters, ensuring accurate query execution. ```python # Escaping the comma before LLC for row in d2.query('producing-entities', curropername='PERCUSSION PETROLEUM OPERATING\, LLC'): print(row) ``` -------------------------------- ### Use Client as Context Manager (Python) Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt This snippet demonstrates using the DeveloperAPIv3 client as a context manager, ensuring automatic cleanup of network sessions. It shows how to perform queries and count records within the context. ```Python from enverus_developer_api import DeveloperAPIv3 # Automatic session cleanup with DeveloperAPIv3(secret_key='your-secret-key') as v3: for row in v3.query('wells', county='REEVES', pagesize=1000): print(row) count = v3.count('wells', deleteddate='null') print(f'Total wells: {count}') # Session automatically closed after exiting context ``` -------------------------------- ### Instantiate DeveloperAPIv3 Client Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Create an instance of the DeveloperAPIv3 class to interact with version 3 of the Enverus Developer API. You will need to provide your secret_key. The access token is automatically managed and available as an attribute. ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3(secret_key='') ``` -------------------------------- ### Retrieve Access Token and Load Datasets in Parallel (Python) Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt This snippet demonstrates how to retrieve an access token once and then use it to load multiple datasets in parallel using multiprocessing. It includes functions for client instantiation and dataset loading with CSV writing. ```Python import os import csv from multiprocessing import Process from enverus_developer_api import DirectAccessV2 # Retrieve access token once ACCESS_TOKEN = DirectAccessV2( client_id=os.getenv('DIRECTACCESS_CLIENT_ID'), client_secret=os.getenv('DIRECTACCESS_CLIENT_SECRET') ).access_token def load_dataset(endpoint, **options): """Load dataset to CSV in parallel process""" # Create client with shared access token client = DirectAccessV2( client_id=os.getenv('DIRECTACCESS_CLIENT_ID'), client_secret=os.getenv('DIRECTACCESS_CLIENT_SECRET'), access_token=ACCESS_TOKEN ) with open(f'{endpoint}.csv', mode='w') as f: writer = csv.writer(f) for i, row in enumerate(client.query(endpoint, **options), start=1): if i == 1: writer.writerow(row.keys()) writer.writerow(row.values()) if i % options.get('pagesize', 100000) == 0: print(f'Wrote {i} records for {endpoint}') print(f'Completed {endpoint}') # Create parallel processes procs = [ Process(target=load_dataset, kwargs=dict(endpoint='well-rollups', pagesize=10000, deleteddate='eq(null)')), Process(target=load_dataset, kwargs=dict(endpoint='producing-entities', pagesize=100000, deleteddate='eq(null)')), Process(target=load_dataset, kwargs=dict(endpoint='permits', pagesize=100000, deleteddate='eq(null)')) ] # Execute all processes [p.start() for p in procs] [p.join() for p in procs] ``` -------------------------------- ### Helper function to add basemap to plot Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/examples/mapping_rigs.ipynb Defines a helper function `add_basemap` that takes an axes object and zoom level, then adds a terrain basemap from a specified URL to the plot. This function is crucial for providing geographical context to the plotted data. ```python # Create our helper function to generate a basemap in our new plot import contextily as ctx def add_basemap(ax, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png'): xmin, xmax, ymin, ymax = ax.axis() basemap, extent = ctx.bounds2img(xmin, ymin, xmax, ymax, zoom=zoom, url=url) ax.imshow(basemap, extent=extent, interpolation='bilinear') # restore original x/y limits ax.axis((xmin, xmax, ymin, ymax)) ``` -------------------------------- ### DeveloperAPIv3 Initialization with SSL Verification Disabled Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Initialize the DeveloperAPIv3 client with SSL verification disabled, which can be used in environments with custom SSL certificates. ```APIDOC ## DeveloperAPIv3 Initialization with SSL Verification Disabled ### Description Initializes the `DeveloperAPIv3` client, with an option to disable SSL certificate verification. Use with caution. ### Method Instantiation of the `DeveloperAPIv3` class. ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3( secret_key='', verify=False ) ``` ### Response #### Success Response (200) N/A (Client initialization) #### Response Example N/A ``` -------------------------------- ### Initialize DeveloperAPIv3 with SSL Verification Disabled Source: https://github.com/enverus-ea/enverus-developer-api/blob/master/README.md Initializes the DeveloperAPIv3 client with SSL verification disabled. This should be used with caution as it bypasses security checks for HTTPS connections. It's recommended to resolve certificate issues rather than disabling verification. ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3( secret_key='', verify=False ) ``` -------------------------------- ### Export to Pandas DataFrame Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Illustrates how to create pandas DataFrames from Enverus datasets, including options for data type configuration, date parsing, index handling, and custom data transformation using converters. ```APIDOC ## Export to Pandas DataFrame ### Description Create a pandas DataFrame with properly configured data types, date parsing, and index columns. Automatically handles composite primary keys as MultiIndex. ### Method POST (Implicit via `v3.to_dataframe`) ### Endpoint N/A (Client-side operation) ### Parameters #### Query Parameters - **dataset** (string) - Required - The name of the dataset to query. - **pagesize** (integer) - Optional - The number of records to retrieve per page. - **deleteddate** (string) - Optional - Filter for deleted records (e.g., 'null'). - **stateprovince** (string) - Optional - Filter by state or province. - **ENVBasin** (string) - Optional - Filter by basin name. - **fields** (string) - Optional - Comma-separated list of fields to retrieve. - **converters** (dict) - Optional - A dictionary mapping field names to conversion functions. ### Request Example ```python from enverus_developer_api import DeveloperAPIv3 v3 = DeveloperAPIv3(secret_key='your-secret-key') # Create DataFrame with basic query df = v3.to_dataframe('rigs', pagesize=10000, deleteddate='null') print(df.head()) print(df.dtypes) # Create DataFrame with converters to transform data df = v3.to_dataframe( dataset='rigs', deleteddate='null', pagesize=100000, stateprovince='TX', converters={ 'StateProvince': lambda x: 'TEXAS', 'ENVOperator': lambda x: x.replace(',', '') } ) print(df.head(10)) # Reset the DataFrame index df = v3.to_dataframe( 'wells', pagesize=10000, ENVBasin='SACRAMENTO', deleteddate='null' ) df.reset_index(inplace=True) print(df.head(10)) # DataFrame with filtered fields df = v3.to_dataframe( 'permits', fields='PermitApprovedDate,County,Operator', stateprovince='TX', deleteddate='null', pagesize=50000 ) ``` ### Response - **df** (pandas.DataFrame) - A DataFrame containing the queried data. ``` -------------------------------- ### Multiprocessing Pattern Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Shows how to use multiprocessing to query multiple datasets concurrently, enabling efficient parallel data retrieval by sharing a single access token across processes. ```APIDOC ## Multiprocessing Pattern ### Description Use multiprocessing to query multiple datasets concurrently by sharing a single access token across processes. ### Method GET/POST (for API query) ### Endpoint N/A (Client-side operation) ### Parameters N/A (Illustrative pattern, specific parameters depend on the datasets being queried). ### Request Example ```python import os import csv from multiprocessing import Process from enverus_developer_api import DirectAccessV2 # Placeholder for actual multiprocessing implementation # This is a conceptual example. The actual code would involve defining # worker functions that use the shared client and process data. # Example of initializing the client (to be shared or re-initialized in workers) # Ensure proper handling of the secret key or token in a multi-process environment # d2 = DirectAccessV2( # client_id=os.getenv('DIRECTACCESS_CLIENT_ID'), # client_secret=os.getenv('DIRECTACCESS_CLIENT_SECRET') # ) # Define worker functions that query specific datasets # def query_dataset_worker(dataset_name, output_path, client): # query = client.query(dataset_name, pagesize=1000) # # Process or write query results to output_path # pass # Create and start processes # processes = [] # datasets_to_query = ['rigs', 'wells', 'permits'] # for dataset in datasets_to_query: # p = Process(target=query_dataset_worker, args=(dataset, f'/tmp/{dataset}.csv', d2)) # processes.append(p) # p.start() # Wait for all processes to complete # for p in processes: # p.join() print("Multiprocessing pattern example structure.") ``` ### Response N/A (Illustrative pattern; actual response depends on the worker function implementation). ``` -------------------------------- ### Multiprocessing with Enverus DirectAccessV2 Source: https://context7.com/enverus-ea/enverus-developer-api/llms.txt Presents a pattern for utilizing Python's `multiprocessing` module to query multiple datasets concurrently. This approach allows for efficient parallel data retrieval by sharing a single API access token across different processes. ```python import os import csv from multiprocessing import Process from enverus_developer_api import DirectAccessV2 # The rest of the multiprocessing example would follow here. ```