Skip to main content

Zero dependency lib for python

Project description

Zeroncy

A simple python tool to make your projet more decoupled.

Just put your project variables on a config file instead store in encironment variable. You can use a .env for json file...

PyPI version Coverage Tests Code style: black License: GPL v2

Installing

pip install zeroncy

How to Use

  1. Using .env file
  • create a .env file in project root and set variables...

    DATABASE_URL=postgres://user:pwd@localhost:5432/psql
    ALLOWED_HOSTS=localhost, 127.0.0.0.1
    PORT=5000
    
  • Then you could use your variables on your settings module...

    >>> import zeroncy
    
    >>> zeroncy.config()
    
    >>> zeroncy.get("DATABASE_URL")
    'postgres://user:pwd@localhost:5432/psql'
    
    # If you want a diferent type you can pass the cast parameter
    
    >>> zeroncy.get("PORT", cast=int)
    5000
    
    # If your var has more than one value, you must set the many parameter to true...
    
    >>> zeroncy.get("ALLOWED_HOSTS", many=True)
    ['localhost', '127.0.0.0.1']
    
  1. Using .env.json file
  • Create a .env.json file on project root:

    {
        "DATABASE_URL": "postgres://user:pwd@localhost:5432/psql",
        "ALLOWED_HOSTS": "localhost, 127.0.0.0.1",
        "PORT": 5000
    }
    
  • Then you could use on a similar way as the previous

    >>> import zeroncy
    
    >>> zeroncy.config(dict) # passes dict as parameter
    
    >>> zeroncy.get("DATABASE_URL")
    'postgres://user:pwd@localhost:5432/psql'
    
    >>> zeroncy.get("PORT")
    5000
    
    >>> zeroncy.get("ALLOWED_HOSTS", many=True)
    ['localhost', '127.0.0.0.1']
    
    # Note that on Json config you don't need to passes cast parameter for other types (Integer in this example)
    

References


LICENSE

                GNU GENERAL PUBLIC LICENSE
                   Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

Project details


Download files

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

Source Distribution

zeroncy-1.0.2.tar.gz (19.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page