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 functions including a simple function including parameterized querying.

Install

Install from pypi pip install eq-sql-connector or clone and use poetry install 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:

poetry run pytest --cov=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-0.1.2.tar.gz (4.8 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-0.1.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eq_sql_connector-0.1.2.tar.gz
  • Upload date:
  • Size: 4.8 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-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c6fc81f0f1935e9236d59fc77671fbad64011545996ccdd27215131c9b881cb2
MD5 4cd31013d574805161183732d7b1656c
BLAKE2b-256 cc66f9f299f30190b6be3580723db88caf7541da0f3defb6ddce61ec146027ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: eq_sql_connector-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 16820b26d980d8943b9afc983d2c695d6d644553e7deb371991651c2cce7f0d9
MD5 ec7dc4889daca21f6084d4b5c3025e41
BLAKE2b-256 a668a0e644c377177d8da017f56fdaa6e141710c638f75e93f6bd64ccbfb06ac

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