Skip to main content

os.environ proxy based on django-environ

Project description

musette enables application configuration by providing a proxy to os.environ which allows:

  • type-casting of environment values
  • updating the environment via plaintext key-value properties files
  • shell-style interpolation

musette is a direct fork of django-environ with significant changes. Although it is intended for Django settings configuration it does not actually require Django itself.

The original module (django-environ) was a merge of:

Basic usage

from musette import environ'')

DEBUG = environ.bool("DEBUG")

Django Settings

This is your file before you have installed musette:

DEBUG = True

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'database',
        'USER': 'user',
        'PASSWORD': 'githubbedpassword',
        'HOST': '',
        'PORT': '8458',
    'extra': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'database.sqlite'

SECRET_KEY = 'notsecret'

    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': [
            '', '', '',
    'redis': {
        'BACKEND': 'redis_cache.cache.RedisCache',
        'LOCATION': '',
        'OPTIONS': {
            'CLIENT_CLASS': 'redis_cache.client.DefaultClient',
            'PASSWORD': 'redis-githubbed-password',


from musette import Environment

env = Environment(DEBUG=(bool, False),)'')

DEBUG = env('DEBUG') # False if not in os.environ

    'default': env.db(),
    'extra': env.db('SQLITE_URL', default='sqlite:////tmp/my-tmp-sqlite.db')


    'default': env.cache(),
    'redis': env.cache('REDIS_URL')

Properties Files

A properties or “env” file is plain text file containing one or more key := value or key = value lines, where values may optionally refer to other environment values via shell-style variables:

that := something
this := ${that}

How to install

$ pip install musette

How to use

There is an Environment class and a convenient instance of that class called environ:

>>> from musette import Environment
>>> env = Environment(
        DEBUG=(bool, False),
>>> env('DEBUG')
>>> env('DEBUG', default=True)

>>> open('.myenv', 'a').write('DEBUG=on\n')
>>> env('DEBUG')

>>> open('.myenv', 'a').write('INT_VAR=1010\n')
>>>'INT_VAR'), env.str('INT_VAR')
1010, '1010'

>>> open('.myenv', 'a').write('DATABASE_URL=sqlite:///my-local-sqlite.db\n')
>>> env.db()
{'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'my-local-sqlite.db', 'HOST': '', 'USER': '', 'PASSWORD': '', 'PORT': ''}

Environment by default provides an effective proxy to the os.environ data dictionary, but you can pass in any other dict instead:

>>> from musette import Environment
>>> _environ = {}
>>> env = Environment(_environ, DEBUG=True)
>>> _environ['DEBUG']

If you are neither passing in a configuration dict or any schema values then you can just use the environ instance:

>>> import os
>>> from musette import environ
>>> set(os.environ.keys()) == set(environ.keys())

Supported Types

  • str
  • bool
  • int
  • float
  • json
  • list (FOO=a,b,c)
  • dict (BAR=key=val;foo=bar)
  • url
  • db_url
    • PostgreSQL: postgres://, pgsql://, psql:// or postgresql://
    • PostGIS: postgis://
    • MySQL: mysql:// or mysql2://
    • MySQL for GeoDjango: mysqlgis://
    • SQLITE: sqlite://
    • SQLITE with SPATIALITE for GeoDjango: spatialite://
    • LDAP: ldap://
  • cache_url
    • Database: dbcache://
    • Dummy: dummycache://
    • File: filecache://
    • Memory: locmemcache://
    • Memcached: memcache://
    • Python memory: pymemcache://
    • Redis: rediscache://
  • search_url
    • ElasticSearch: elasticsearch://
    • Solr: solr://
    • Whoosh: whoosh://
    • Simple cache: simple://
  • email_url
    • SMTP: smtp://
    • SMTPS: smtps://
    • Console mail: consolemail://
    • File mail: filemail://
    • LocMem mail: memorymail://
    • Dummy mail: dummymail://


$ git clone
$ cd musette
$ python test

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for musette, version 0.5.10
Filename, size File type Python version Upload date Hashes
Filename, size musette-0.5.10.tar.gz (18.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page