Skip to content

Python library to simplify working with the environment

License

Notifications You must be signed in to change notification settings

topanim/WConfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WConfig: Library to simplify working with the environment

PyPI version

Libraries used

Installation

pip install whaox-wconfig

Features

  • Modularity
  • Type conversion
  • Auto-return or handling

Setup

First, let's set up ours .env file

API_KEY=YOUR_API_KEY

API_URL=https://example.com

LOGGING=False

Usage

Don't forget add this lines to your main.py file

from dotenv import load_dotenv

load_dotev()

Now let's create a config class

class WConfig:
    
    @VAR("API_KEY")
    def api_key(self): pass

You can easily get variables from your .env file

config = WConfig()
config.api_key()

>>> YOUR_API_KEY

Type conversion

You can cast the value to the desired type, to do this, specify the type in the _T parameter

NOTE: Supported types are str, bool, int, float

class WConfig:
    
    @VAR("LOGGING", bool)
    def logging(self) -> bool: pass

Handling

You can handle the received value if you need by setting the handle flag to True.

class WConfig:
    
    @VAR("API_KEY", handle=True)
    def api_key(self, var): 
        return 'prefix-' + var

Modularity

You can split your config class into modules

@Config("API")
class Api:
    
    @VAR("KEY")
    def key(self): pass
    
    @VAR("URL")
    def url(self): pass


class WConfig:
    api = Api()
    
    @VAR("LOGGING", bool)
    def logging(self): pass   
config = WConfig()

config.api.key()
config.logging()

About

Python library to simplify working with the environment

Topics

Resources

License

Stars

Watchers

Forks

Languages