Questions tagged [python-decouple]

Python decouple is frequently used within Python Web Frameworks (e.g. Django or Flask) to store instance settings, so they can be changed without the need of redeploying the whole project or app.

Decouple claims to work better than enviromental variables. Here's an example:

Let's say you have an envvar DEBUG=False. If you run:

if os.environ['DEBUG']:
    print True
else:
    print False

It will print True, because os.environ['DEBUG'] returns the string "False". Since it's a non-empty string, it will be evaluated as True.

Decouple addresses this caveats by allowing casting of values:

config('DEBUG', cast=bool)

References

25 questions
40
votes
8 answers

Django - cannot import name 'config' from 'decouple'

I'm trying to run this project locally but when i try manage.py makemigrations i keep getting the following error: ImportError: cannot import name 'config' from 'decouple' Here are my steps: Clone the repository from github Create a virtual…
Jack022
  • 867
  • 6
  • 30
  • 91
30
votes
3 answers

How do you use python-decouple to load a .env file outside the expected paths?

I'm forced to keep my .env file in a non-standard path outside the root of my project (in a separate directory altogether). Let's say I have my Django project in /var/projects/my_project, though I have my .env file in /opt/envs/my-project/.env where…
John Adjei
  • 1,483
  • 2
  • 14
  • 19
12
votes
1 answer

Creating .env file on the root of the project

I am trying to download a Django project from github and one of the requirements is:"As the project uses python-decouple you will need to create a file named .env on the root of the project with three values, as…
Ismail Sarenkapic
  • 140
  • 1
  • 2
  • 9
9
votes
7 answers

ImportError: No module named 'decouple' while deploying on Heroku

I was trying to deploy my django project on heroku from heroku cli. So I created an app and then I ran git push heroku master from the project directory. Then I got the errors: remote: -----> $ python manage.py collectstatic --noinput remote: …
sphoenix
  • 3,327
  • 5
  • 22
  • 40
3
votes
1 answer

Difference between django-environ and python-decouple?

Here I have used django-environ to set the environment variable but it is giving me SECRET_KEY error.How to properly configure the environmental variable? I also used the python-decouple for this instead of django-environ which works fine but didn't…
D_P
  • 802
  • 10
  • 32
2
votes
3 answers

How use django with decouple

I am trying to use python-decouple for sensitive data in my project but When i use decouple.config for SECRET_KEY it raises an error error Traceback (most recent call last): File "manage.py", line 21, in main() File "manage.py",…
Hamedio
  • 65
  • 9
2
votes
2 answers

In settings.py, how should environment variables be loaded/set if they're only used in one environment?

I have a Django application where I'm handling environment variables using python-decouple and separate .env files. This works fine for variables that exist in both development and production environments, such as DEBUG. SECRET_KEY =…
1
vote
0 answers

How do I get django decouple to use my updated env vars?

I use DECOUPLE in my Django project and its awesome. However, I recently changed an env variable to a new key and after restarting the server, it still used the old env key. I used a print statement to see the key being used. Does it cache the old…
1
vote
1 answer

Django can't find me .env variables? decouple.UndefinedValueError: ENVIORNMENT not found. Declare it as envvar or define a default value

I am very new to Django and trying to configure python-decouple to use .env variables. I am getting DB_PASSWORD not found. Declare it as envvar or define a default value. when trying to run the server. The .env file is located in the root directory.…
Spiral
  • 917
  • 1
  • 9
  • 15
1
vote
1 answer

How to use different .env files with python-decouple

I am working on a django project that I need to run it with Docker. In this project I have multiples .env files: .env.dev, .env.prod, .env.staging. Is there a right way to manage all this file with the package python-decouple? I've search for a…
1
vote
2 answers

How to use environment variables in views.py in Django?

I am using python-decouple 3.4 for setting up environment variables for my django application. My .env file is in the same directory as that of manage.py. Except for SECRET_KEY (in settings.py), loading other environment variables in either…
zester
  • 165
  • 3
  • 12
1
vote
0 answers

How to set key-value within .env file using python-decouple

I am experimenting with the python-decouple library using below code: if __name__ == '__main__': TEMPLATE_DEBUG = config('TEMPLATE_DEBUG') DATABASE_URL = config('DATABASE_URL') print(TEMPLATE_DEBUG,'\n',DATABASE_URL) …
1
vote
1 answer

Parse .ini sections with python-decouple

Documentation has a paradigm where the only section is called settings This seems to be the default namespace for python-decouple thus if you have: [settings] DEBUG=True you can parse the config with: from decouple import config DEBUG =…
stelios
  • 2,679
  • 5
  • 31
  • 41
1
vote
2 answers

Decouple module error running Django 1.8 project using Django 1.9

Currently, I am using latest version of Django 1.9. I have a project that is written in Django 1.8 When I tried to runserver, I encountered the following error What should I do as I do not want to downgrade to Django 1.8 to run the…
3d510
  • 65
  • 3
  • 11
0
votes
0 answers

ImportError: No module named 'decouple' using pyenv

as I'm using pyenv-virtualenv I have created my Pipfile and I'm trying to run the server with the command pipenv run python manage.py runserver but I'm getting the error: from decouple import config, Csv ImportError: No module named 'decouple'. I…
1
2