Lightweight, thread-safe, multi-project Python interface to dbt-core
Built with the tools and technologies:
Overview
dbt-core-interface is a lightweight, high-performance Python interface for working directly with (v1.8+). It allows developers to manage and run dbt projects entirely in memory using an intuitive Python API—enabling runtime SQL compilation, macro evaluation, SQLFluff linting/formatting, and more, all through FastAPI or local usage.
dbt-core
It supports dynamic multi-project environments, automatic re-parsing, file watchers, and asynchronous usage. It is the foundation for more complex interfaces such as dbt-fastapi and is designed to rapidly prototype ideas outside the constraints of the dbt-core repo itself.
Features
🧐 In-memory dbt-core 1.8+ interface with full RuntimeConfig hydration
⚡ Fast, thread-safe SQL compilation and execution via FastAPI
🔬 Interactive linting and formatting with SQLFluff
🌐 Live REST API server via FastAPI
🌍 Supports multiple projects simultaneously using DbtProjectContainer
When running the FastAPI server, use these endpoints for quality monitoring:
# Add a quality check
curl -X POST 'http://localhost:8581/api/v1/quality/checks' \
-H 'X-dbt-Project: /your/dbt_project' \
-d '{
"name": "row_count_check",
"check_type": "row_count",
"model_name": "my_model",
"severity": "warning",
"config": {"min_rows": 1, "max_rows": 1000000}
}'
# List all quality checks
curl 'http://localhost:8581/api/v1/quality/checks?project_dir=/your/dbt_project'
# Run quality checks
curl -X POST 'http://localhost:8581/api/v1/quality/run?project_dir=/your/dbt_project&model_name=my_model'
# Add an alert channel
curl -X POST 'http://localhost:8581/api/v1/quality/alerts' \
-H 'X-dbt-Project: /your/dbt_project' \
-d '{
"channel_type": "webhook",
"config": {"url": "https://hooks.slack.com/..."}
}'
Generic Test Library
dbt-core-interface includes a comprehensive library of reusable generic dbt tests that can be easily configured via YAML schema files:
from dbt_core_interface import DbtProject, GenericTestLibrary
# Load your project
project = DbtProject(project_dir="/path/to/dbt_project")
# Initialize the test library
library = GenericTestLibrary(project)
# List all available tests
for test in library.list_tests():
print(f"{test.name}: {test.description}")
# Generate schema.yml with suggested tests
columns = {"id": {}, "email": {}, "status": {}}
schema_yml = library.generate_schema_yml("users", columns)
print(schema_yml)
Available Generic Tests
unique: Ensures a column has unique values (no duplicates)
not_null: Ensures a column has no null values
relationships: Ensures referential integrity between tables
accepted_values: Ensures column values are from a specified list
recency: Checks data freshness within a time window
cardinality_equals: Ensures distinct count matches another table
The library can automatically suggest appropriate tests based on column naming patterns:
# Get suggestions for specific columns
for col_name in ["id", "user_id", "email", "status"]:
suggestions = library.suggest_tests_for_column(col_name)
for suggestion in suggestions:
print(f"{col_name}: {suggestion.test_type.value}")
For detailed documentation, see src/dbt_core_interface/generic_tests/docs.md.
License
This project is licensed under the MIT License. See the LICENSE file for more info.
Acknowledgments
Thanks to the dbt-core maintainers and contributors whose work makes this project possible.
Works well with
Use together with dbt-core-interface: extensions, drivers, servers and companion tools.
dbt-corePythie’s Index: 90With dbt, data analysts and engineers can build analytics the way engineers build applications.24.8M downloads/mo