Skip to main content

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

Not forget add this lines to your main.py file

from dotenv import load_dotenv

load_dotev()

Now let's create a config class

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

You can easily get variables from your .env file

config = Config()
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 Config:
    
    @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 Config:
    
    @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 Config:
    api = Api()
    
    @VAR("LOGGING", bool)
    def logging(self): pass   
config = Config()

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

Metadata

Release files for whaox-wconfig 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whaox-wconfig 1.0.3
File Size Uploaded
whaox-wconfig-1.0.3.tar.gz 5.0 kB Details

Release files / whaox-wconfig-1.0.3.tar.gz

Download URL whaox-wconfig-1.0.3.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
45649435b9c6dcf12af006d2311991efcaf871c969b517d5a2b6d39df9063a75
BLAKE2b-256 checksum
How to use checksums
fc0897c8545b0fd37d0af6a0d12b6e254a02faea74e3f3a5b70c41017cedd060
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page