Skip to main content

PDM Reader

pdm-datareader logo

Runs on Windows Runs on MacOS Runs on RHEL7 SCM Compliance PyPI - Version

pdm-datareader is a python package for reading Production Data Mart (PDM) data into pandas DataFrames. It can read data in two ways:

  • Through the PDM API (recommended for new users) — read one PDM view at a time with filters, column selection and sorting. No ODBC driver or Equinor network connection needed. See API usage.
  • With SQL directly against the PDM database — full SQL, but requires the ODBC driver and the Equinor network. See SQL usage.

Both handle authentication for end users with user impersonation (sign-in with your Equinor account), and both return only the data your PDM field access allows.

Pull requests, feature requests and issues are welcomed using the GitHub Project Repository or as a ServiceNow ticket directed to Production Data Mart.

Install

  1. Ensure that ODBC Driver for SQL Server is installed (only needed for SQL usage). Currently supports both v18 and v17.
    This driver is bundled with the Microsoft SQL Client package in AccessIT, and should be pre installed on linux environments. Instructions for installing on MacOS can be found here..
  2. MacOS users must install unixodbc (only needed for SQL usage). See https://pypi.org/project/pyodbc/ for current instructions.
  3. Linux users must apply for Linux compliant device exclusion to get multifactor authentication to work.
  4. Finally install the latest version of the python package using:
    pip install pdm-datareader

Development

Install uv and use Python 3.11–3.14. From the repository root:

uv sync 

API usage

Available from version 2.6.0. The API reads one PDM view at a time and returns it as a pandas DataFrame.

Note: Looking for how to query PDM with SQL directly? See SQL usage.

1. Get a subscription key

All requests to the PDM API go through a gateway that requires a subscription key in addition to your Equinor sign-in. Create your own key in the Equinor API portal. Make sure it is an "Enterprise" type subscription key.

Your account also needs PDM data access: the same field-based roles as for the database, applied for in AccessIT.

Treat the key like a password: don't put it in notebooks, scripts or git repositories. Set it as an environment variable instead:

# Windows (PowerShell), for the current user permanently
[Environment]::SetEnvironmentVariable("PDM_APIM_SUBSCRIPTION_KEY", "<your key>", "User")
# macOS / Linux, e.g. in ~/.bashrc or ~/.zshrc
export PDM_APIM_SUBSCRIPTION_KEY="<your key>"

Restart your terminal or IDE afterwards. Alternatively, set it in code from a source of your own with set_subscription_key(...).

2. Check the connection

import pdm_datareader as pdm

pdm.ping()          # e.g. {'version': '3.0', 'databaseCheckPassed': True}

The first call opens a browser window to sign in with your Equinor account. Later calls reuse the sign-in silently. If you have several Equinor accounts, choose one with pdm.get_api_token(username="abcd") (short name or full email address) before your first call.

3. Read data

import datetime as dt
from pdm_datareader import read_api_view, Range

df = read_api_view(
    "WellProdDay",
    filters={
        "COUNTRY": "NO",
        "PROD_DAY": Range(dt.date(2024, 1, 1), dt.date(2024, 1, 31)),
    },
    columns=["PROD_DAY", "WELL_UWI", "ALLOC_OIL_VOL_SM3"],
    order_by="PROD_DAY DESC, WELL_UWI",
)
print(df)
  • The first argument is the view name in the API, e.g. WellProdDay (the SQL view PDMVW.WELL_PROD_DAY). Views and their columns are described on the PDM documentation site.
  • All matching rows are returned by default, just like a SQL query without TOP. For large views, always use filters and columns to limit the result.
  • Date-time columns are returned as datetime64.

Arguments

Argument Description Example
filters Column name → filter. See Filters. {"COUNTRY": "NO"}
columns Columns to return. Default: all columns. ["PROD_DAY", "WELL_UWI"]
order_by Sort order, one or more columns, ASC/DESC. Default: the view's default order. "PROD_DAY DESC, WELL_UWI"
top Maximum number of rows. Default: all rows. Combined with order_by, sorting happens first. top=10
skip Number of rows to skip, for paging yourself. See Paging. skip=1000
timeout Seconds to wait for a response. Default: 300. timeout=600
verbose Print progress messages. verbose=True

Filters

All filters in filters must match (AND). A filter value can be:

Filter Matches Example
A single value Equal to the value {"COUNTRY": "NO"}
A list Any of the values {"WELL_UWI": ["NO 15/9-F-12", "NO 15/9-F-14"]}
Range(a, b) Between a and b, both included. Leave out one end for an open range: Range(a) or Range(end=b). Numbers and dates. {"PROD_DAY": Range(dt.date(2024, 1, 1), dt.date(2024, 1, 31))}
Like(text) Contains text {"WELL_NAME": Like("F-1")}
StartsLike(text) Starts with text {"FIELD_NAME": StartsLike("JOHAN")}
EndsLike(text) Ends with text {"FIELD_NAME": EndsLike("SVERDRUP")}
IsNull() Empty (null) {"COMMENTS": IsNull()}
In([...]) Any of the values or filters {"EVENT_ID": In([Range(2, 5), 7])}
Raw(expression) Sent to the API as written (advanced) {"EVENT_ID": Raw("RANGE(2 | 5)")}

All helpers are imported from pdm_datareader, e.g. from pdm_datareader import Range, Like, IsNull.

Filter values cannot contain the characters | , [ ] ( ) ", because the API has no way to escape them; you'll get a ValueError before anything is sent. Use Like/StartsLike/EndsLike on a part of the value without those characters instead.

Paging

read_api_view fetches all rows in one request. If you want to fetch a large result in pages yourself, combine top, skip and an order_by on columns that together uniquely identify each row. Without a unique order, rows can be repeated or missed between pages.

page_size, skip, pages = 50_000, 0, []
while True:
    page = read_api_view("WellProdDay", filters={...}, order_by="PROD_DAY, WELL_UWI",
                     top=page_size, skip=skip)
    pages.append(page)
    if len(page) < page_size:
        break
    skip += page_size

Often it's simpler to split a large request by date instead, e.g. one read_api_view call per month with a Range filter.

Moving from SQL to the API

SQL read_api_view
FROM PDMVW.WELL_PROD_DAY read_api_view("WellProdDay", ...)
SELECT A, B columns=["A", "B"]
WHERE A = 'x' AND B = 1 filters={"A": "x", "B": 1}
WHERE A IN ('x', 'y') filters={"A": ["x", "y"]}
WHERE D BETWEEN '2024-01-01' AND '2024-01-31' filters={"D": Range(dt.date(2024, 1, 1), dt.date(2024, 1, 31))}
WHERE A LIKE '%x%' / 'x%' / '%x' Like("x") / StartsLike("x") / EndsLike("x")
WHERE A IS NULL filters={"A": IsNull()}
ORDER BY D DESC, A order_by="D DESC, A"
SELECT TOP(10) top=10

Joins, GROUP BY/aggregates, OR between different columns and calculated columns are not available in the API. Read each view with read_api_view and combine or aggregate the DataFrames with pandas, or use SQL for those queries.

Troubleshooting

Error Meaning
SubscriptionKeyError The subscription key is missing or was rejected by the gateway. Check that PDM_APIM_SUBSCRIPTION_KEY is set and that the key is valid.
PdmAuthError Sign-in failed or access was denied.
PdmTimeoutError The request took too long. Narrow the filters, request fewer columns, or split the request (e.g. by date).
PdmApiError Other errors from the API. The message includes a TraceId when available; include it when reporting issues.
Empty result You may not have access to the field. pdm.user_access() lists the fields and facilities you have access to.

SQL usage

Requires the ODBC driver (see Install) and a connection to the Equinor network.

See examples/demo.py or try the code below that queries PDM and retrieves data:

import datetime as dt
from pdm_datareader import query

# Example with parameter bindings to avoid SQL injection issues (recommended)
sql = '''
SELECT top(100) * 
FROM PDMVW.WELL_PROD_DAY 
WHERE COUNTRY = :countrycode 
AND PROD_DAY = :startdate
'''
df = query(sql, params={'countrycode': 'NO',
                 'startdate': dt.datetime(2022, 1, 1)})
print(df)

# Example without parameters (not recommended)
sql = 'SELECT TOP(1) * FROM PDMVW.WELL_PROD_DAY'
df = query(sql)
print(df)

Metadata

Release files for pdm-datareader 2.6.0

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

Source distribution (sdist)

Source distribution for pdm-datareader 2.6.0
File Size Uploaded Provenance Actions
pdm_datareader-2.6.0.tar.gz 19.8 kB With provenance Details for pdm_datareader-2.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdm-datareader 2.6.0
File Interpreter ABI Platform Actions
pdm_datareader-2.6.0-py3-none-any.whl Python 3 none any Details for pdm_datareader-2.6.0-py3-none-any.whl

Total release size: 40.3 kB

Release files / pdm_datareader-2.6.0.tar.gz

Download URL pdm_datareader-2.6.0.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1671ffd52e647bf33d293dccd9894e8c418ccb9450f0b2e74500e69efab682a1
BLAKE2b-256 checksum
How to use checksums
cee56250faac735f4460413360bb6b795c0e2e285514578239aee39e67c2ff4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / pdm_datareader-2.6.0-py3-none-any.whl

Download URL pdm_datareader-2.6.0-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ee2885cebaae172e6c2a4526e2f86f9602bcc9e67bddc8275d6acfe3f478dcc
BLAKE2b-256 checksum
How to use checksums
ecc969f4e2f94d81850edc86bcc93b8b50d63a2c084f804479181e6cda5f93e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for pdm-datareader 2.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pdm_datareader-2.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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