Astronomer Cosmos is an open-source Python library that seamlessly integrates dbt (data build tool) Core projects with Apache Airflow. It allows users to orchestrate dbt models as native Airflow DAGs and Task Groups, providing enhanced observability, retries, and test execution directly within the Airflow UI. The library is actively maintained with frequent releases, evolving to support new dbt features like Fusion and various execution modes for optimal performance.
pip install astronomer-cosmosVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create an Airflow DAG that orchestrates a dbt project using Astronomer Cosmos's `DbtDag` class. It configures a dbt project path, maps an Airflow connection to a dbt profile, and sets an execution environment for dbt. Replace placeholder values like `AIRFLOW_DB_CONN_ID` and `DBT_EXECUTABLE_PATH` with your actual environment variables or paths. Ensure your dbt project (e.g., 'jaffle_shop') is accessible from your Airflow environment.
Upgrade your Airflow environment to version 2.9 or higher before upgrading to Cosmos 1.14.0 or later.
Increase the `core.dagbag_import_timeout` Airflow configuration. Consider refactoring Cosmos DAGs to use a pre-generated `manifest.json` file, or explicitly setting `LoadMode.DBT_MANIFEST` and pre-generating the manifest during image build or deployment.
Astronomer Cosmos strongly recommends installing dbt and its adapters within a separate Python virtual environment, distinct from the one where Airflow is installed. The `dbt_executable_path` in `ExecutionConfig` should then point to this isolated virtual environment's dbt executable.
If this behavior is not desired, configure `RenderConfig` to use `TestBehavior.AFTER_ALL`. For tests with multiple parents, consider setting `should_detach_multiple_parents_tests=True` in `RenderConfig` (introduced in Cosmos 1.8.2) to create separate test tasks for better isolation.
This issue is often related to concurrent dbt processes and temporary file management. Ensure proper temporary directory handling, explicitly configure `TMPDIR` environment variables if needed, and increase task retries (e.g., `retries=2`) as re-runs often succeed.
Create distinct `DbtTaskGroup` instances for your snapshots and models, and chain them in your Airflow DAG to enforce the desired sequence (e.g., snapshots before models).
pip install astronomer-cosmos
from astronomer_cosmos import DbtDag
from astronomer_cosmos.task_group import DbtTaskGroup
pip install flask_limiter==3.12
Update the import statement to reflect the new location of 'PackageFinder'.