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
![Install Certificates Install Certificates](https://images.archbee.com/-kIqrMCOJgmgBmRpzgKo2/mxi1oCbL7N7uDmNG47_RM_image.png?format=webp)
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
![Document image Document image](https://files.readme.io/07e451f-image.png)
a) Create daily production input (Example data demonstrated)
b) Upsert daily production to API client
API response when upserted successfully
![Document image Document image](https://images.archbee.com/-kIqrMCOJgmgBmRpzgKo2/FW54_bcuC14BnlbgT4NYd_image.png?format=webp)
API response when error occurred (Example: uwi of upserted daily production doesn't exist in wellheader)
![Document image Document image](https://images.archbee.com/-kIqrMCOJgmgBmRpzgKo2/DKukdrYbo7_7ziSw9VO7n_image.png?format=webp)
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
![Document image Document image](https://images.archbee.com/-kIqrMCOJgmgBmRpzgKo2/0lqzoCBWvrCIE2kJLN7Wj_image.png?format=webp)
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)
![Document image Document image](https://images.archbee.com/-kIqrMCOJgmgBmRpzgKo2/BiV_UavZIyThC00zytyX2_image.png?format=webp)
If uwi doesn't exist in database, API response will return 400 error code.
![Document image Document image](https://images.archbee.com/-kIqrMCOJgmgBmRpzgKo2/o0sdIKPNgdnlTIjXMFff5_image.png?format=webp)
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
![Doc contributor](https://s3.amazonaws.com/archbee-animals/gorilla.png)