Python Tutorial
Author(s): Clark Chen and Kyle Vessey, November 2022
Developer Prerequisites:
- Internet connection
Data Schema: Please read the Data Schema Fundamentals document before using the API. Database CRUD operations are performed via the API and therefore it is important to think of each HTTP REST operation (POST/GET/DELETE) as SQL transaction (UPSERT/SELECT/DELETE)
Visualizing Data:
Data inserted or modified using this tutorial can be visualized using the web portal application(s) at https://app.onxecta.com. The portal contains a Model Quality tool where you can see what data is in the system, the validity of the data and when the data was last modified.
Create a new folder on your machine to begin building your project
Open the folder, and create a new Python file
The Xecta Data API Client is hosted as a Python package in PyPi
To install the API Client, run the following command in your command prompt window:
This will pull the compiled package from PyPi and install it on your machine.
To initialize and configure you project to include the SDK, follow this code sample
Error Initializing Certificate and Key: When calling the xecta_api.authenticate method, you must pass in the environment URL, signed certificate (xecta-data-api.pem), and your private key (xecta-data-api.key)
If you get an error message stating: [SSL: CERTIFICATE_VERIFY_FAILED], try the following fix:
MacOS:Â Navigate to Macintosh HD > Applications > PythonX.X folder (where X is the version of Python you are using) > then double click on "Install Certificates.command" file
a) Required Python libraries - Pandas and Numpy
b) Optional Python libraries - tqdm (For displaying progress bar of data processing)
a) Data Preparation - Import well header from source data (.xlsx data demonstrated in this tutorial)
b) Create a function to convert field names in camel case to snake case
- This function will be used for other source data as well
c) Change field names and data type to be consistent with data schema
d) Upsert wellheader data to API client
Potential Error: Null values in non-nullable fields
Example: Null in field 'lat' will return error message when upserting
a) Create daily production input (Example data demonstrated)
b) Upsert daily production to API client
API response when upserted successfully

API response when error occurred (Example: uwi of upserted daily production doesn't exist in wellheader)

a) Import daily production from source data (.xlsx data demonstrated in this tutorial)
b) Input data preparation - change field names and data type to be consistent with data schema
Batch Processing:
In order to reduce the payload, it is recommended to upsert the daily production of each well in batches
Potential Error: API response will return 400 error code when uwi of daily production doesn't exist in database 
If daily production has been successfully deleted, API response will return number of records which was just deleted.
(In this example 658 records were deleted)

If uwi doesn't exist in database, API response will return 400 error code.

a) Data Preparation (Data import and format conversion)
b) Upsert wellbore record
a) Data preparation (Data import and formation conversion)
b) Upsert deviation survey
a) Data Preparation (Data import and data format conversion)
b) Upsert casing data
a) Data preparation (Data import and data format conversion)
b) Upsert tubing records
a) Data Preparation (Data import and formation conversion)
b) Upsert formation