DBT Copilot Python
A set of utility functions for running Django & Flask apps in AWS ECS via AWS Copilot.
Using dbt-copilot-python
Supported Python versions
3.9, 3.10, 3.11, 3.12 and 3.13.
Installation
pip install dbt-copilot-python
With celery
If you are using celery, you should also install an appropriate version of celery using your project's package manager, or our built-in extra.
# Poetry
poetry add celery
# Pip
pip install celery
pip freeze | grep "^celery==" >> requirements.txt
# Pipenv
pipenv install celery
OR
# Poetry
poetry add dbt-copilot-python[celery]
# Pip
pip install dbt-copilot-python[celery]
pip freeze | grep "^celery==" >> requirements.txt
# Pipenv
pipenv install dbt-copilot-python[celery]
With error tracking
If you intend on using the error tracking filter, you should also install an appropriate version of ddtrace using your project's package manager, or our built-in extra.
# Poetry
poetry add ddtrace
# Pip
pip install ddtrace
pip freeze | grep "^ddtrace==" >> requirements.txt
# Pipenv
pipenv install ddtrace
OR
# Poetry
poetry add dbt-copilot-python[error-tracking]
# Pip
pip install dbt-copilot-python[error-tracking]
pip freeze | grep "^ddtrace==" >> requirements.txt
# Pipenv
pipenv install dbt-copilot-python[error-tracking]
Usage
ALLOWED_HOSTS setting
Add the ECS container IP to ALLOWED_HOSTS setting so that the Application Load Balancer (ALB) healthcheck will succeed:
from dbt_copilot_python.network import setup_allowed_hosts
ALLOWED_HOSTS = [...]
ALLOWED_HOSTS = setup_allowed_hosts(ALLOWED_HOSTS)
Celery health check
Install the library with celery.
Add the health check in your application's Celery config file...
from dbt_copilot_python.celery_health_check import healthcheck
celery_app = Celery("application_name")
...
celery_app = healthcheck.setup(celery_app)
Add the health check to the Celery worker service in docker-compose.yml...
healthcheck:
test: [ "CMD-SHELL", "python -m dbt_copilot_python.celery_health_check.healthcheck" ]
interval: 10s
timeout: 5s
retries: 2
start_period: 5s
In your *-deploy codebase, add the health check to the Celery worker service in copilot/celery-worker/manifest.yml...
healthcheck:
command: [ "CMD-SHELL", "launcher bash -c 'python -m dbt_copilot_python.celery_health_check.healthcheck'" ]
interval: 10s
timeout: 5s
retries: 2
start_period: 10s
DATABASES setting
To configure the DATABASES setting from an RDS JSON object stored in AWS Secrets Manager, there are two options.
-
Configure the
DATABASESsetting to use a database URL (recommended):Note: This is dependent on the
dj-database-urlpackage which can be installed viapip install dj-database-url.import dj_database_url from dbt_copilot_python.database import database_url_from_env DATABASES = { "default": dj_database_url.config( default=database_url_from_env("DATABASE_ENV_VAR_KEY") ) }
-
Configure the
DATABASESsetting to use a dictionary containing the settings:from dbt-copilot-python.database import database_from_env DATABASES = database_from_env("DATABASE_ENV_VAR_KEY")
Error tracking
To enable error tracking for logs you must attach the DatadogErrorTrackingFilter to any of the loggers which you'd like to track logs emitted at a level >=logging.ERROR.
Generally speaking you could do something as follows
import logging
from dbt_copilot_python import DatadogErrorTrackingFilter
logger = logging.getLogger()
logger.addFilter(DatadogErrorTrackingFilter())
Contributing to dbt-copilot-python
Requirements
- Poetry;
pip install poetry
Install dependencies & pre-commit hooks
poetry install && poetry run pre-commit install
Run the tests
poetry run pytest
Publishing
To publish the Python package dbt-copilot-python, you will need an API token.
- Acquire API token from Passman.
- Request access from the SRE team.
- Note: You will need access to the
platformgroup in Passman.
- Run
poetry config pypi-token.pypi <token>to add the token to your Poetry configuration.
Update the version, as the same version cannot be published to PyPi.
poetry version patch
More options for the version command can be found in the Poetry documentation. For example, for a minor version bump: poetry version minor.
Update the CHANGELOG.md with details of the changes you've made.
Build the Python package.
poetry build
Publish the Python package.
Note: Make sure your Pull Request (PR) is approved and contains the version upgrade in pyproject.toml before publishing the package.
poetry publish
Check the PyPi Release history to make sure the package has been updated.
For an optional manual check, install the package locally and test everything works as expected.
Metadata
Release files for dbt-copilot-python 2.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 | |
|---|---|---|---|---|
| dbt_copilot_python-2.1.0.tar.gz | 6.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dbt_copilot_python-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / dbt_copilot_python-2.1.0.tar.gz
| Download URL | dbt_copilot_python-2.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccbbdc1749eb1d13ad03eaa72ac337c7618e74ec8c54e17baf599377d1b476aa
|
|
BLAKE2b-256 checksum How to use checksums |
fc5271d46fb700e70b7204b836321c41d1a37f784935ef0a978e2296048e90ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.14.2 Linux/5.15.0-1100-aws-fips
|
Release files / dbt_copilot_python-2.1.0-py3-none-any.whl
| Download URL | dbt_copilot_python-2.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f725c10d12fbed9e26a2d612f34e7b7839ab91a003be048d9929beaea349657f
|
|
BLAKE2b-256 checksum How to use checksums |
c89476acab15c1c5f8e3f883be9a7884fded337e8f91381e9b90baf9e24da341
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.14.2 Linux/5.15.0-1100-aws-fips
|
Security for dbt-copilot-python 2.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.
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.