prefect-sqlalchemy
The prefect-sqlalchemy helps you connect to a database in your Prefect flows.Getting Started
Prerequisites
Install prefect-sqlalchemy
Install or update to the latest version of the prefect-sqlalchemy library and dependencies.
Register newly installed block types
Register the block types in the prefect-sqlalchemy module to make them available for use.Examples
Save credentials to a block
To use theload
method on Blocks, you must have a block saved through code or saved through the UI.
driver
and database
arguments:
Work with databases in a flow
To set up a table, use theexecute
and execute_many
methods.
Use the fetch_many
method to retrieve data in a stream until there’s no more data.
Use the SqlAlchemyConnector
as a context manager, to ensure that the SQLAlchemy engine and any connected resources are closed properly after you’re done with them.
Async support
SqlAlchemyConnector
supports async workflows. Just be sure to save, load, and use an async driver, as in the example below.