Code Monkey home page Code Monkey logo

sys-vars's Introduction

sys-vars

Access system variables in your code as native Python data types.

Usage

Requires Python 3.8+

Load system variables for used in applications as secrets, variables, and other related contexts as native Python data types. Searches for a file in SYS_VARS_PATH, falling back to os.enviorn. If the package is installed with the dotenv extra (pip install sys-vars[dotenv]), there is a final check in the contents of a .env file located in SYS_VARS_PATH, if one exists.

SYS_VARS_PATH must be a defined OS environment variable that is set before app start. If it is not found, a KeyError exception will be raised.

import sys_vars


# Returns <class 'str'>
# Default values can be specified if the key is missing
sys_vars.get("HOST_ADDRESS", default="localhost")

# Returns <class 'bool'>
# Default values are supported for casting methods too
# Also treats "t", "true", "y", "yes" as True value
sys_vars.get_bool("DEBUG_MODE", default=False)

# Returns <class 'datetime.datetime'>
sys_vars.get_datetime("LAST_SYNC_RUN")

# Returns <class 'float'>
sys_vars.get_float("pi")

# Returns <class 'int'>
sys_vars.get_int("THE_MEANING_OF_LIFE")

# Returns <class 'dict'> or <class 'list'>
# Automatically decodes JSON strings into dictionaries/lists
sys_vars.get_json("CONFIGURED_TERMS")

# Returns <class 'pathlib.Path'>
sys_vars.get_path("CONFIG_PATH")

# Raises `sys_vars.SysVarNotFoundError`
sys_vars.get("DOES_NOT_EXIST")

Building

  1. Install Poetry 1.6.0+
  2. Run poetry install
  3. Run poetry build
  4. Tests can be run via the provided VS Code test runner config.

The resulting .whl file will be located at ./dist/sys_vars-<x.y.z>-py3-none-any.whl

sys-vars's People

Contributors

dependabot[bot] avatar le717 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.