Metadata-Version: 2.4
Name: eq-sql-connector
Version: 0.1.2
Summary: SQL Database connector to connect to public client app registrations using delegated permissions (MSAL).
License: MIT
License-File: LICENSE
Author: Åsmund Våge Fannemel
Author-email: asmf@equinor.com
Requires-Python: >=3.10,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: msal-bearer (>=1.4.3,<2.0.0)
Requires-Dist: pandas (>=2.3.2,<3.0.0)
Requires-Dist: pyodbc (>=5.2.0,<6.0.0)
Requires-Dist: sqlalchemy (>=2.0.43,<3.0.0)
Description-Content-Type: text/markdown

# 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](https://github.com/equinor/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:

```python
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:

```python
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:

```bash
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


