dagster-db
Dagster IO managers and type handlers for databases. Wraps the standard IO managers with useful functions that can be scpecific to each type handler, and provides better metadata out of the box.
- Apply custom generic transformations to ensure all outputs comply with database.
- Apply custom validation checks before deleting from / writing to the database.
- Add custom metadata.
Use polars, pandas or execute a jinja-templated SQL query on the database
with the custom SqlQuery class which builds dagsters powerful table slice
logic into an io-manager ready framework.
Use TypeHandlers out of the box, or extend to implement custom behaviours.
duckdb
Installation
uv add dagster-db[duckdb]
Definition
import dagster as dg
from dagster_db import build_custom_duckdb_io_manager
custom_io_manager = build_custom_duckdb_io_manager().configured({"database": "./.tmp/database.duckdb"})
defs = dg.Definitions(
...,
resources={"io_manager": custom_io_manager},
)
Usage
import dagster as dg
import polars as pl
from dagster_db import SqlQuery
@dg.asset
def my_asset(context: dg.AssetExecutionContext) -> pl.DataFrame:
return pl.DataFrame({"a": [1, 2, 3]})
@dg.asset
def my_asset_downstream(
context: dg.AssetExecutionContext,
my_asset: SqlQuery,
) -> SqlQuery:
return SqlQuery("SELECT *, a+1 AS b FROM {{ my_asset }}", my_asset)
Why should I use dagster-db instead of just querying via database resources?
Partitioned assets
If you have a partitioned asset, then when you use it in a downstream asset, it will need to be filtered for the partition we are running for (via the partition mapping). The IO manager already handles this using table slice functionality.
e.g. so if you have a date partitioned asset my_asset, when you create a SQL
query: SELECT * FROM {{ my_asset }} in a downstream asset, we get the
partition selection for free. The load_input methods can render this into
SELECT * FROM (SELECT * FROM my_asset WHERE partition_expr >= ... AND partition_expr < ...),
whereas we'd have to do this manually using the resources.
Standardised features and metadata
When you use any IO manager in dagster, dagster truncates the table for you, before inserting the records. Using database resources, you would have to make all of these database calls yourself.
@dg.asset(deps=[my_asset_upstream])
def my_asset_downstream(duckdb: DuckDbResource):
my_asset_downstream_query = "SELECT *, True AS new_col FROM my_asset_upstream"
duckdb.sql("DELETE FROM my_asset_downstream")
duckdb.sql(f"INSERT INTO my_asset_downstream ({my_asset_downstream_query})")
vs.
@dg.asset()
def my_asset_downstream(my_asset_upstream: SqlQuery):
return SqlQuery("SELECT *, True AS new_col FROM {{ my_asset_upstream }}", my_asset_upstream=my_asset_upstream)
You also get the opportunity to add features to your IO manager, such as adding useful metadata, primary key validation, etc. that apply to every asset without having to call manually within asset code in each asset.
Therefore, tt allows the continued separation of IO code and business logic which is such a great feature of dagster.
Different databases in different environments
Many workflows may consist of a duckdb database for local development, but bigquery or
postgresql for production.
These clients and resources have completely different method names and arguments.
The best place to handle these differences, would be in TypeHandlers, which would
clear your asset of further IO code.
Metadata
Release files for dagster-db 0.3.2
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 | Actions |
|---|---|---|---|---|
| dagster_db-0.3.2.tar.gz | 119.4 kB | Without provenance | Details for dagster_db-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dagster_db-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for dagster_db-0.3.2-py3-none-any.whl |
Total release size: 136.3 kB
Release files / dagster_db-0.3.2.tar.gz
| Download URL | dagster_db-0.3.2.tar.gz |
|---|---|
| Size | 119.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04a8d136a0bfe28bf44ab4c01be231350d4da319181931755a08981e950ce55d
|
|
BLAKE2b-256 checksum How to use checksums |
d59f20933fed035449eb9595a695abadde2cecd362e42cbe1a834e815f07bdcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.9
|
Release files / dagster_db-0.3.2-py3-none-any.whl
| Download URL | dagster_db-0.3.2-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
865baa9cbb32d858989ba44555c30e0bba8d23573965808ef5e9e8315987a0aa
|
|
BLAKE2b-256 checksum How to use checksums |
3e6c1a16321a844d3d64d7a555e5ff133c05145d597187029425afee47dfcf1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.9
|
Security for dagster-db 0.3.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.