You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Forcing yourself to only log via decorators can have some positive side effects:
360
358
If you feel like you would like to add some logging within a function, this can be an indicator that the code block in question is a candidate to be refactored into a separate function.
@@ -368,24 +366,27 @@ All of these parameters should be handed to the code via environment variables.
368
366
369
367
> A litmus test for whether an app has all config correctly factored out of the code is whether the codebase could be made open source at any moment, without compromising any credentials.[^6]
370
368
371
-
That is why this template comes with [`python-dotenv`](https://pypi.org/project/python-dotenv/) pre-installed.
372
-
Simply create a file named `.env` in the project root folder and enter your configration parameters:
369
+
To store your secrets create a file named `.env` in the project root folder and enter your configration parameters:
373
370
```ini
374
371
DATABASE_URL=postgres://localhost:1337/dbname
375
372
DATBASE_USER=myusername
376
373
DATABASE_PASSWORD=topsneaky
377
374
```
375
+
Scripts run via [`just`](https://github.com/casey/just) automatically load these entries as environment variables.
376
+
```bash
377
+
just run src/script.py
378
+
```
378
379
In your code you can access these screts like this:
379
380
```python
381
+
# src/script.py
380
382
import os
381
-
from dotenv import load_dotenv
382
-
383
-
load_dotenv()
384
383
385
384
database_url = os.getenv("DATABASE_URL")
386
385
```
387
386
Thanks to the `.gitignore`, the `.env` file will not get committed into the git repository.
388
387
388
+
Alternatively you can also use [`python-dotenv`](https://pypi.org/project/python-dotenv/) to load secrets from `.env` files.
0 commit comments