Skip to main content

SQL Database connector to connect to public client app registrations using delegated permissions (MSAL).

Project description

eq-sql-connector

A small python package to handle authentication and act as a generic database connector.

It supports multiple authentication flows using msal-bearer and contains a few basic database access functions including parameterized querying.

Install

Install from pypi pip install eq-sql-connector or clone and use uv sync as a developer.

Usage

For connecting to Equinor database, typically only database and url_prod is required when creating DBConnector:

from eq_sql_connector import DBConnector


connector = DBConnector(
	database="my_database",
	url_prod="my-server.database.windows.net",
)

df = connector.query("SELECT TOP 5 * FROM my_table")
print(df)

# Example with parameterized querye+
df = connector.query(
	"SELECT TOP 10 * FROM my_table WHERE asset_id IN :param",
	params=[1001, 1002, 1003],
)

connector.reset_engine()

Advanced example with an explicit Authenticator and a parameterized query:

from msal_bearer import Authenticator
from eq_sql_connector import DBConnector


authenticator = Authenticator(
	tenant_id="<your-tenant-id>",
	client_id="<your-client-id>",
	scopes=["https://database.windows.net/.default"],
	user_name="<your-user>@equinor.com",
)

connector = DBConnector(
	database="my_database",
	url_prod="my-server.database.windows.net",
	authenticator=authenticator,
)

df = connector.query(
	"SELECT TOP 10 * FROM my_table WHERE asset_id IN :param",
	params=[1001, 1002, 1003],
)

print(df.head())

# Dispose pooled connections when done
connector.reset_engine()

Testing

Run tests with coverage from the repository root:

uv run pytest --cov=src/eq_sql_connector --cov-report=term-missing

Current test suite covers:

  • SQL driver detection and connection string generation
  • Connector and DBConnector initialization and validation
  • Query behavior (including parameter handling)
  • Engine caching, reset, and pool configuration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eq_sql_connector-1.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eq_sql_connector-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file eq_sql_connector-1.0.1.tar.gz.

File metadata

  • Download URL: eq_sql_connector-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Darwin/25.5.0

File hashes

Hashes for eq_sql_connector-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fde4a5c2371609865df13a5111f0b3579409b40283cc1ec47fa8b00c0641553f
MD5 57f4b2d3d4379c0fa85ed3cf5a03137f
BLAKE2b-256 63ebdff5fd7e2b8b1bb52d7fed14b4a705e6d46145ed085cb917ada3e78fd2aa

See more details on using hashes here.

File details

Details for the file eq_sql_connector-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: eq_sql_connector-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Darwin/25.5.0

File hashes

Hashes for eq_sql_connector-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a2de1e9961cabc369ee69567ef3a4bd6fa0df16c4f0e117839a03050a0b317e
MD5 14167974f8d87350b46f6ebfc05e7fb2
BLAKE2b-256 9428ad88b8079645bb9c832b8a6acea40b2a0ac2a2ecfdbc1daca7d980437b5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page