dbt-copilot-python 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbt-copilot-python
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Helper functions to run Django and Flask applications in AWS Copilot/ECS.
5
5
  Author: Department for Business and Trade Platform Team
6
6
  Author-email: sre-team@digital.trade.gov.uk
@@ -28,24 +28,46 @@ pip install dbt-copilot-python
28
28
 
29
29
  ### Usage
30
30
 
31
- In `settings.py`:
31
+ In `settings.py`...
32
32
 
33
- 1. Add the ECS container IP to `ALLOWED_HOSTS` so that the Application Load Balancer (ALB) healthcheck will succeed:
33
+ #### ALLOWED_HOSTS
34
+
35
+ Add the ECS container IP to `ALLOWED_HOSTS` so that the Application Load Balancer (ALB) healthcheck will succeed:
36
+
37
+ ```
38
+ from dbt_copilot_python.network import setup_allowed_hosts
39
+
40
+ ALLOWED_HOSTS = [...]
41
+
42
+ ALLOWED_HOSTS = setup_allowed_hosts(ALLOWED_HOSTS)
43
+ ```
44
+
45
+ #### DATABASES
46
+
47
+ To configure the `DATABASES` setting from an RDS JSON object stored in AWS Secrets Manager, there are two options.
48
+
49
+ 1. Configure the `DATABASES` setting to use a database URL (recommended):
50
+
51
+ Note: This is dependent on the [`dj-database-url`](https://pypi.org/project/dj-database-url/) package which can be installed via `pip install dj-database-url`.
34
52
 
35
53
  ```
36
- from dbt_copilot_python.network import setup_allowed_hosts
37
-
38
- ALLOWED_HOSTS = [...]
39
-
40
- ALLOWED_HOSTS = setup_allowed_hosts(ALLOWED_HOSTS)
54
+ import dj_database_url
55
+
56
+ from dbt_copilot_python.database import database_url_from_env
57
+
58
+ DATABASES = {
59
+ "default": dj_database_url.config(
60
+ default=database_url_from_env("DATABASE_ENV_VAR_KEY")
61
+ )
62
+ }
41
63
  ```
42
64
 
43
- 2. Configure the `DATABASES` setting from an RDS JSON object stored in SSM Parameter Store:
65
+ 2. Configure the `DATABASES` setting to use a dictionary containing the settings:
44
66
 
45
67
  ```
46
- from dbt-copilot-python import aws_database_config
47
-
48
- DATABASES = aws_database_config("ENVIRONMENT_KEY")
68
+ from dbt-copilot-python.database import database_from_env
69
+
70
+ DATABASES = database_from_env("DATABASE_ENV_VAR_KEY")
49
71
  ```
50
72
 
51
73
  ## Contributing to `dbt-copilot-python`
@@ -0,0 +1,75 @@
1
+ # DBT Copilot Python
2
+
3
+ ![](https://codebuild.eu-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiTG41bUNVdHN1b3NRS0hTYUlmMktLbnNNQzEyTlpMRDBlYlZiV1ZjNnl4b3dyMXl0R3VIUEVIbGVnYVJWbHd0OVZndVhURFpnckp5dWx0R0llMVpHUktzPSIsIml2UGFyYW1ldGVyU3BlYyI6ImthS3RRRUtOYkljSUVVUHMiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=main)
4
+
5
+ A set of utility functions for running Django & Flask apps in AWS ECS via AWS Copilot.
6
+
7
+ ## Using `dbt-copilot-python`
8
+
9
+ ### Installation
10
+
11
+ ```
12
+ pip install dbt-copilot-python
13
+ ```
14
+
15
+ ### Usage
16
+
17
+ In `settings.py`...
18
+
19
+ #### ALLOWED_HOSTS
20
+
21
+ Add the ECS container IP to `ALLOWED_HOSTS` so that the Application Load Balancer (ALB) healthcheck will succeed:
22
+
23
+ ```
24
+ from dbt_copilot_python.network import setup_allowed_hosts
25
+
26
+ ALLOWED_HOSTS = [...]
27
+
28
+ ALLOWED_HOSTS = setup_allowed_hosts(ALLOWED_HOSTS)
29
+ ```
30
+
31
+ #### DATABASES
32
+
33
+ To configure the `DATABASES` setting from an RDS JSON object stored in AWS Secrets Manager, there are two options.
34
+
35
+ 1. Configure the `DATABASES` setting to use a database URL (recommended):
36
+
37
+ Note: This is dependent on the [`dj-database-url`](https://pypi.org/project/dj-database-url/) package which can be installed via `pip install dj-database-url`.
38
+
39
+ ```
40
+ import dj_database_url
41
+
42
+ from dbt_copilot_python.database import database_url_from_env
43
+
44
+ DATABASES = {
45
+ "default": dj_database_url.config(
46
+ default=database_url_from_env("DATABASE_ENV_VAR_KEY")
47
+ )
48
+ }
49
+ ```
50
+
51
+ 2. Configure the `DATABASES` setting to use a dictionary containing the settings:
52
+
53
+ ```
54
+ from dbt-copilot-python.database import database_from_env
55
+
56
+ DATABASES = database_from_env("DATABASE_ENV_VAR_KEY")
57
+ ```
58
+
59
+ ## Contributing to `dbt-copilot-python`
60
+
61
+ ### Requirements
62
+
63
+ - [Poetry](https://python-poetry.org/); `pip install poetry`
64
+
65
+ ### Install dependencies & pre-commit hooks
66
+
67
+ ```
68
+ poetry install && poetry run pre-commit install
69
+ ```
70
+
71
+ ### Run the tests
72
+
73
+ ```
74
+ poetry run pytest
75
+ ```
@@ -29,3 +29,17 @@ def database_from_env(environment_key, **extra_keys):
29
29
  """
30
30
 
31
31
  return {"default": setup_database(environment_key, **extra_keys)}
32
+
33
+
34
+ def database_url_from_env(environment_key):
35
+ """
36
+ Set up the default database URL from a Copilot database environment
37
+ variable.
38
+
39
+ Usage in settings.py:
40
+
41
+ DATABASES = { 'default': dj_database_url.config(default=database_url_from_env("MY_DATABASE")) }
42
+ """
43
+ config = json.loads(os.environ[environment_key])
44
+
45
+ return "{engine}://{username}:{password}@{host}:{port}/{dbname}".format(**config)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dbt-copilot-python"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "Helper functions to run Django and Flask applications in AWS Copilot/ECS."
5
5
  authors = ["Department for Business and Trade Platform Team <sre-team@digital.trade.gov.uk>"]
6
6
  readme = "README.md"
@@ -1,53 +0,0 @@
1
- # DBT Copilot Python
2
-
3
- ![](https://codebuild.eu-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiTG41bUNVdHN1b3NRS0hTYUlmMktLbnNNQzEyTlpMRDBlYlZiV1ZjNnl4b3dyMXl0R3VIUEVIbGVnYVJWbHd0OVZndVhURFpnckp5dWx0R0llMVpHUktzPSIsIml2UGFyYW1ldGVyU3BlYyI6ImthS3RRRUtOYkljSUVVUHMiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=main)
4
-
5
- A set of utility functions for running Django & Flask apps in AWS ECS via AWS Copilot.
6
-
7
- ## Using `dbt-copilot-python`
8
-
9
- ### Installation
10
-
11
- ```
12
- pip install dbt-copilot-python
13
- ```
14
-
15
- ### Usage
16
-
17
- In `settings.py`:
18
-
19
- 1. Add the ECS container IP to `ALLOWED_HOSTS` so that the Application Load Balancer (ALB) healthcheck will succeed:
20
-
21
- ```
22
- from dbt_copilot_python.network import setup_allowed_hosts
23
-
24
- ALLOWED_HOSTS = [...]
25
-
26
- ALLOWED_HOSTS = setup_allowed_hosts(ALLOWED_HOSTS)
27
- ```
28
-
29
- 2. Configure the `DATABASES` setting from an RDS JSON object stored in SSM Parameter Store:
30
-
31
- ```
32
- from dbt-copilot-python import aws_database_config
33
-
34
- DATABASES = aws_database_config("ENVIRONMENT_KEY")
35
- ```
36
-
37
- ## Contributing to `dbt-copilot-python`
38
-
39
- ### Requirements
40
-
41
- - [Poetry](https://python-poetry.org/); `pip install poetry`
42
-
43
- ### Install dependencies & pre-commit hooks
44
-
45
- ```
46
- poetry install && poetry run pre-commit install
47
- ```
48
-
49
- ### Run the tests
50
-
51
- ```
52
- poetry run pytest
53
- ```