Skip to main content

Query Drilling Data with Python

This guide finds visible drilling wells through the Platform API, then reads corva#wits records for one selected well.

Prerequisites

  • Python 3
  • The requests package
  • A read-capable API key stored as CORVA_API_KEY

Find drilling wells

import os
import requests

headers = {"Authorization": f"API {os.environ['CORVA_API_KEY']}"}

response = requests.get(
"https://api.corva.ai/v2/wells",
headers=headers,
params={
"visibility": "visible",
"status[]": ["active", "paused", "complete"],
"state[]": ["drilling", "drilled_not_completed", "completed"],
"fields[]": ["well.name", "well.asset_id", "well.state", "well.status"],
"sort": "name",
"order": "asc",
"per_page": 1000,
},
timeout=30,
)
response.raise_for_status()
wells = response.json()["data"]

for well in wells:
attributes = well["attributes"]
print(attributes["name"], attributes["asset_id"])

Read WITS records

Set asset_id to one of the values printed above.

import json

asset_id = 12345
cursor = 0
records = []

while True:
response = requests.get(
"https://data.corva.ai/api/v1/data/corva/wits/",
headers=headers,
params={
"query": json.dumps({
"asset_id": asset_id,
"timestamp": {"$gt": cursor},
}),
"sort": json.dumps({"timestamp": 1}),
"limit": 10000,
"fields": (
"timestamp,asset_id,data.hole_depth,data.bit_depth,"
"data.hook_load,data.rotary_torque,data.weight_on_bit,"
"data.rop,data.rotary_rpm,data.standpipe_pressure"
),
},
timeout=30,
)
response.raise_for_status()
batch = response.json()

if not batch:
break

records.extend(batch)
cursor = batch[-1]["timestamp"]

print(f"Retrieved {len(records)} records")

During development, use a small limit and a recent timestamp range before exporting an entire well.