{"id":22308764,"url":"https://github.com/ratson/dj-environ","last_synced_at":"2025-03-26T01:28:55.196Z","repository":{"id":57422783,"uuid":"86697439","full_name":"ratson/dj-environ","owner":"ratson","description":null,"archived":false,"fork":false,"pushed_at":"2017-03-30T11:58:34.000Z","size":165,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T22:51:28.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ratson.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-30T11:58:16.000Z","updated_at":"2017-09-28T16:56:51.000Z","dependencies_parsed_at":"2022-08-27T05:25:38.687Z","dependency_job_id":null,"html_url":"https://github.com/ratson/dj-environ","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fdj-environ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fdj-environ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fdj-environ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fdj-environ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ratson","download_url":"https://codeload.github.com/ratson/dj-environ/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245571263,"owners_count":20637311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T20:15:12.877Z","updated_at":"2025-03-26T01:28:55.169Z","avatar_url":"https://github.com/ratson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"==========\nDj-environ\n==========\n\nDj-environ allows you to utilize 12factor inspired environment variables to configure your Django application.\n\n|pypi| |downloads| |license|\n\n\nThis is your `settings.py` file before you have installed **dj-environ**\n\n.. code-block:: python\n\n    import os\n    SITE_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))\n\n    DEBUG = True\n    TEMPLATE_DEBUG = DEBUG\n\n    DATABASES = {\n        'default': {\n            'ENGINE': 'django.db.backends.postgresql_psycopg2',\n            'NAME': 'database',\n            'USER': 'user',\n            'PASSWORD': 'githubbedpassword',\n            'HOST': '127.0.0.1',\n            'PORT': '8458',\n        }\n        'extra': {\n            'ENGINE': 'django.db.backends.sqlite3',\n            'NAME': os.path.join(SITE_ROOT, 'database.sqlite')\n        }\n    }\n\n    MEDIA_ROOT = os.path.join(SITE_ROOT, 'assets')\n    MEDIA_URL = 'media/'\n    STATIC_ROOT = os.path.join(SITE_ROOT, 'static')\n    STATIC_URL = 'static/'\n\n    SECRET_KEY = '...im incredibly still here...'\n\n    CACHES = {\n        'default': {\n            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',\n            'LOCATION': [\n                '127.0.0.1:11211', '127.0.0.1:11212', '127.0.0.1:11213',\n            ]\n        },\n        'redis': {\n            'BACKEND': 'django_redis.cache.RedisCache',\n            'LOCATION': '127.0.0.1:6379:1',\n            'OPTIONS': {\n                'CLIENT_CLASS': 'django_redis.client.DefaultClient',\n                'PASSWORD': 'redis-githubbed-password',\n            }\n        }\n    }\n\nAfter:\n\n.. code-block:: python\n\n    import environ\n    root = environ.Path(__file__) - 3 # three folder back (/a/b/c/ - 3 = /)\n    env = environ.Env(DEBUG=(bool, False),) # set default values and casting\n    environ.Env.read_env() # reading .env file\n\n    SITE_ROOT = root()\n\n    DEBUG = env('DEBUG') # False if not in os.environ\n    TEMPLATE_DEBUG = DEBUG\n\n    DATABASES = {\n        'default': env.db(), # Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ\n        'extra': env.db('SQLITE_URL', default='sqlite:////tmp/my-tmp-sqlite.db')\n    }\n\n    public_root = root.path('public/')\n\n    MEDIA_ROOT = public_root('media')\n    MEDIA_URL = 'media/'\n    STATIC_ROOT = public_root('static')\n    STATIC_URL = 'static/'\n\n    SECRET_KEY = env('SECRET_KEY') # Raises ImproperlyConfigured exception if SECRET_KEY not in os.environ\n\n    CACHES = {\n        'default': env.cache(),\n        'redis': env.cache('REDIS_URL')\n    }\n\nYou can also pass ``read_env()`` an explicit path to the ``.env`` file.\n\nCreate a ``.env`` file:\n\n.. code-block:: bash\n\n    DEBUG=on\n    # DJANGO_SETTINGS_MODULE=myapp.settings.dev\n    SECRET_KEY=your-secret-key\n    DATABASE_URL=psql://urser:un-githubbedpassword@127.0.0.1:8458/database\n    # SQLITE_URL=sqlite:///my-local-sqlite.db\n    CACHE_URL=memcache://127.0.0.1:11211,127.0.0.1:11212,127.0.0.1:11213\n    REDIS_URL=rediscache://127.0.0.1:6379:1?client_class=django_redis.client.DefaultClient\u0026password=redis-un-githubbed-password\n\n\nHow to install\n==============\n\n::\n\n    $ pip install dj-environ\n\n\nHow to use\n==========\n\nThere are only two classes, ``environ.Env`` and ``environ.Path``\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import environ\n    \u003e\u003e\u003e env = environ.Env(\n            DEBUG=(bool, False),\n        )\n    \u003e\u003e\u003e env('DEBUG')\n    False\n    \u003e\u003e\u003e env('DEBUG', default=True)\n    True\n\n    \u003e\u003e\u003e open('.myenv', 'a').write('DEBUG=on')\n    \u003e\u003e\u003e environ.Env.read_env('.myenv') # or env.read_env('.myenv')\n    \u003e\u003e\u003e env('DEBUG')\n    True\n\n    \u003e\u003e\u003e open('.myenv', 'a').write('\\nINT_VAR=1010')\n    \u003e\u003e\u003e env.int('INT_VAR'), env.str('INT_VAR')\n    1010, '1010'\n\n    \u003e\u003e\u003e open('.myenv', 'a').write('\\nDATABASE_URL=sqlite:///my-local-sqlite.db')\n    \u003e\u003e\u003e env.read_env('.myenv')\n    \u003e\u003e\u003e env.db()\n    {'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'my-local-sqlite.db', 'HOST': '', 'USER': '', 'PASSWORD': '', 'PORT': ''}\n\n    \u003e\u003e\u003e root = env.path('/home/myproject/')\n    \u003e\u003e\u003e root('static')\n    '/home/myproject/static'\n\n\nSupported Types\n===============\n\n- str\n- bool\n- int\n- float\n- json\n- list (FOO=a,b,c)\n- tuple (FOO=(a,b,c))\n- dict (BAR=key=val,foo=bar) #environ.Env(BAR=(dict, {}))\n- dict (BAR=key=val;foo=1.1;baz=True) #environ.Env(BAR=(dict(value=unicode, cast=dict(foo=float,baz=bool)), {}))\n- url\n- path (environ.Path)\n- db_url\n    -  PostgreSQL: postgres://, pgsql://, psql:// or postgresql://\n    -  PostGIS: postgis://\n    -  MySQL: mysql:// or mysql2://\n    -  MySQL for GeoDjango: mysqlgis://\n    -  SQLITE: sqlite://\n    -  SQLITE with SPATIALITE for GeoDjango: spatialite://\n    -  Oracle: oracle://\n    -  LDAP: ldap://\n- cache_url\n    -  Database: dbcache://\n    -  Dummy: dummycache://\n    -  File: filecache://\n    -  Memory: locmemcache://\n    -  Memcached: memcache://\n    -  Python memory: pymemcache://\n    -  Redis: rediscache://\n- search_url\n    - ElasticSearch: elasticsearch://\n    - Solr: solr://\n    - Whoosh: whoosh://\n    - Xapian: xapian://\n    - Simple cache: simple://\n- email_url\n    - SMTP: smtp://\n    - SMTP+SSL: smtp+ssl://\n    - SMTP+TLS: smtp+tls://\n    - Console mail: consolemail://\n    - File mail: filemail://\n    - LocMem mail: memorymail://\n    - Dummy mail: dummymail://\n\nTips\n====\n\nUsing unsafe characters in URLs\n-------------------------------\n\nIn order to use unsafe characters you have to encode with ``urllib.parse.encode`` before you set into ``.env`` file.\n\n.. code-block::\n\n    DATABASE_URL=mysql://user:%23password@127.0.0.1:3306/dbname\n\n\nSee https://perishablepress.com/stop-using-unsafe-characters-in-urls/ for reference.\n\nEmail settings\n--------------\n\nIn order to set email configuration for django you can use this code:\n\n.. code-block:: python\n\n    EMAIL_CONFIG = env.email_url(\n        'EMAIL_URL', default='smtp://user@:password@localhost:25')\n\n    vars().update(EMAIL_CONFIG)\n\n\nTests\n=====\n\n::\n\n    $ git clone https://github.com/ratson/dj-environ.git\n    $ cd dj-environ/\n    $ python setup.py test\n\n\nCredits\n=======\n\nThis is a fork of `django-environ \u003chttps://github.com/joke2k/django-environ\u003e`_,\nwhich has the following differences,\n\n* Support PostgreSQL URL using unix domain socket paths, e.g. postgres:////var/run/postgresql/db\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/dj-environ.svg?style=flat-square\u0026label=version\n    :target: https://pypi.python.org/pypi/dj-environ\n    :alt: Latest version released on PyPi\n\n.. |downloads| image:: https://img.shields.io/pypi/dm/dj-environ.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/dj-environ\n    :alt: Monthly downloads\n\n.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n    :target: https://raw.githubusercontent.com/ratson/dj-environ/master/LICENSE.txt\n    :alt: Package license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratson%2Fdj-environ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fratson%2Fdj-environ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratson%2Fdj-environ/lists"}