Skip to main content

Petrinex Python API

Load Alberta Petrinex data (Volumetrics, NGL) into Spark/pandas DataFrames.

PyPI version Downloads Build Status Python 3.8+ License: MIT

Features

  • ✅ Databricks Serverless - Full Unity Catalog support
  • ✅ Memory Efficient - Handles 100+ files without OOM
  • ✅ Zero Config - Automatic ZIP extraction, encoding, error handling
  • ✅ Multiple Data Types - Volumetrics (Vol) and NGL support

Note: Currently supports Alberta (AB) jurisdiction only.

Quick Start

pip install petrinex
from petrinex import PetrinexClient

# Volumetrics data
client = PetrinexClient(spark=spark, data_type="Vol")
df = client.read_spark_df(updated_after="2025-12-01")

# NGL and Marketable Gas
ngl_client = PetrinexClient(spark=spark, data_type="NGL")
ngl_df = ngl_client.read_spark_df(updated_after="2025-12-01")

API

Load Data

# Spark DataFrame (recommended)
df = client.read_spark_df(updated_after="2025-12-01")

# pandas DataFrame
pdf = client.read_pandas_df(updated_after="2025-12-01")

# Date range
df = client.read_spark_df(from_date="2021-01-01", end_date="2023-12-31")

Date Parameters:

  • updated_after="2025-12-01" - Files modified after this date
  • from_date="2021-01-01" - All data from production month onwards
  • end_date="2023-12-31" - Optional end date (use with from_date)

Download Files

Download Petrinex files to your local machine. Files are extracted from ZIP and organized in subdirectories by production month:

# Download recent updates
paths = client.download_files(
    output_dir="./petrinex_data",
    updated_after="2025-12-01"
)
# Creates: ./petrinex_data/2025-12/Vol_2025-12.csv

# Historical range
paths = client.download_files(
    output_dir="./data",
    from_date="2021-01-01",
    end_date="2023-12-31"
)

Large Data Loads (Unity Catalog)

For large data loads (20+ files), write directly to Unity Catalog to avoid memory issues and timeouts:

# Write directly to UC table (avoids memory accumulation)
df = client.read_spark_df(
    from_date="2020-01-01",
    uc_table="main.petrinex.volumetrics"
)

# Incremental updates
df = client.read_spark_df(
    updated_after="2025-12-01",
    uc_table="main.petrinex.volumetrics"
)

# Full refresh (truncate first)
spark.sql("TRUNCATE TABLE main.petrinex.volumetrics")
df = client.read_spark_df(from_date="2020-01-01", uc_table="main.petrinex.volumetrics")

Benefits:

  • ✅ No memory accumulation
  • ✅ No Spark Connect timeouts
  • ✅ Automatic schema evolution
  • ✅ Handles 100+ files
  • ✅ Provenance & schema validation

Safety Features:

  • Provenance validation (checks for required columns)
  • Schema validation (ensures compatibility)
  • Schema evolution (adds new columns automatically)
  • Append-only mode (no accidental overwrites)

Databricks

%pip install git+https://github.com/guanjieshen/petrinex-python-api.git

from petrinex import PetrinexClient

client = PetrinexClient(spark=spark, data_type="Vol")
df = client.read_spark_df(updated_after="2025-12-01")
display(df)

See databricks_example.ipynb for complete example.

Data Types

Type Description
Vol Conventional Volumetrics (oil & gas production)
NGL NGL and Marketable Gas Volumes

Installation

# From PyPI
pip install petrinex

# From GitHub
pip install git+https://github.com/guanjieshen/petrinex-python-api.git

# Development
git clone https://github.com/guanjieshen/petrinex-python-api.git
cd petrinex-python-api
pip install -e ".[dev]"

Testing

# Run all tests
pytest tests/ -v

# With coverage
pytest tests/ --cov=petrinex --cov-report=html

# Integration tests (requires network)
pytest tests/ -v -m integration

License

MIT License - Copyright (c) 2026 Guanjie Shen

Metadata

Release files for petrinex 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for petrinex 1.1.1
File Size Uploaded
petrinex-1.1.1.tar.gz 20.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for petrinex 1.1.1
File Interpreter ABI Platform
petrinex-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.8 kB

Release files / petrinex-1.1.1.tar.gz

Download URL petrinex-1.1.1.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6d8dfe9533aae14343695df27f308d0d15afe130d5b9562a592901ad6726e60a
BLAKE2b-256 checksum
How to use checksums
4c1f362d0fdec0e1eb97eacf55ec1dbaa4a661d2dbc2dd5591a3aea94d62ca4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / petrinex-1.1.1-py3-none-any.whl

Download URL petrinex-1.1.1-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56e46825b9bfb21a948808853cb608980fdc6ffb633429fcae106e5a97e594cd
BLAKE2b-256 checksum
How to use checksums
8936b9bccfd347bc135ce4e0f6cc2b41b8fad813a397aadae2127f21e0ba10d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page