prefect-sqlalchemy-entra
A fork of prefect-sqlalchemy
that adds Microsoft Entra ID (Azure AD) token authentication for SQL Server and
Azure SQL, using any TokenCredential from azure.identity.
It installs the prefect_sqlalchemy_entra module with the block types
SQLAlchemy Entra Connector and Async SQLAlchemy Entra Connector, so it can be
installed alongside prefect-sqlalchemy. Apart from the import path and block type
names, the API matches upstream; see the
upstream docs for
everything else.
How it works
When Entra ID authentication is configured, the connector registers a SQLAlchemy
do_connect listener on its engine. Each time the pool opens a new DBAPI connection,
the listener requests an access token from the credential and passes it to the
Microsoft ODBC driver through the SQL_COPT_SS_ACCESS_TOKEN (1256) connection
attribute. It also strips the Trusted_Connection=Yes that SQLAlchemy adds when no
username is set, because that option conflicts with an access token.
Requirements: the mssql+pyodbc (sync) or mssql+aioodbc (async) driver, and the
Microsoft ODBC Driver for SQL Server.
Do not set a username or password in the connection info.
Usage
Pass a credential at runtime
from azure.identity import DefaultAzureCredential
from prefect_sqlalchemy_entra import (
ConnectionComponents, SqlAlchemyConnector, SyncDriver
)
connector = SqlAlchemyConnector(
connection_info=ConnectionComponents(
driver=SyncDriver.MSSQL_PYODBC,
host="myserver.database.windows.net",
port=1433,
database="mydb",
query={"driver": "ODBC Driver 18 for SQL Server"},
)
)
connector.set_token_credential(DefaultAzureCredential())
with connector:
print(connector.fetch_one("SELECT SUSER_SNAME()"))
set_token_credential accepts any synchronous TokenCredential and must be called
before the engine is created. The credential is not saved with the block.
Configure it on a saved block
The entra_id_auth field is saved with the block, so it can also be set from the
Prefect UI:
from prefect_sqlalchemy_entra import (
ConnectionComponents, EntraIdAuth, SqlAlchemyConnector, SyncDriver
)
SqlAlchemyConnector(
connection_info=ConnectionComponents(
driver=SyncDriver.MSSQL_PYODBC,
host="myserver.database.windows.net",
port=1433,
database="mydb",
query={"driver": "ODBC Driver 18 for SQL Server"},
),
entra_id_auth=EntraIdAuth(credential_type="managed_identity", client_id="..."),
).save("azure-sql")
with SqlAlchemyConnector.load("azure-sql") as connector:
...
credential_type |
azure.identity class |
Fields used |
|---|---|---|
default |
DefaultAzureCredential |
client_id (user-assigned managed identity) |
managed_identity |
ManagedIdentityCredential |
client_id (optional) |
client_secret |
ClientSecretCredential |
tenant_id, client_id, client_secret |
azure_cli |
AzureCliCredential |
tenant_id (optional) |
scope defaults to https://database.windows.net/.default. A credential passed to
set_token_credential takes precedence over the one built from entra_id_auth, but
the scope from entra_id_auth still applies.
Async
AsyncSqlAlchemyConnector works the same way with AsyncDriver.MSSQL_AIOODBC
(install aioodbc). Use a synchronous credential: tokens are requested inside
SQLAlchemy's sync connect hook.
Development
uv sync
uv run pytest
Metadata
Release files for prefect-sqlalchemy-entra 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| prefect_sqlalchemy_entra-0.1.0.tar.gz | 244.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prefect_sqlalchemy_entra-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 263.5 kB
Release files / prefect_sqlalchemy_entra-0.1.0.tar.gz
| Download URL | prefect_sqlalchemy_entra-0.1.0.tar.gz |
|---|---|
| Size | 244.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0744b258c02f9036c803e7fc44c856d3625546a21acfbb062941cba86d87f1f8
|
|
BLAKE2b-256 checksum How to use checksums |
64104201b92b2f540dcc4c1bd4e4db7d02c9714591dc093fee82d5363a79e090
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 9, 2026.
Transparency logRelease files / prefect_sqlalchemy_entra-0.1.0-py3-none-any.whl
| Download URL | prefect_sqlalchemy_entra-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c50735dc9b0d92a5f9230b79af1fb76328164b0bd5fd784538ea0e27112d428
|
|
BLAKE2b-256 checksum How to use checksums |
9d95d7cb4bf98e7cf0e5b36d6c8da28a453ddc9ed871aad07fa90b952fb51873
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 9, 2026.
Transparency logSecurity for prefect-sqlalchemy-entra 0.1.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for prefect_sqlalchemy_entra-0.1.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 Oct 9, 2026.
Transparency logA 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.