Git Product home page Git Product logo

envclasses's Introduction

envclasses

image image Test

envclasses is a library to map fields on dataclass object to environment variables.

Installation

pip install envclasses

Usage

Declare a class with dataclass and envclass decorators.

from envclasses import envclass, load_env
from dataclasses import dataclass

@envclass
@dataclass
class Foo:
    v: int

foo = Foo(v=10)
load_env(foo, prefix='foo')
print(foo)

Run the script

$ python foo.py
Foo(v=10)

Run with environment variable

$ FOO_V=100 python foo.py
Foo(v=100)

envclasses's People

Contributors

alexmisk avatar christosvar avatar danidelvalle-frontiers avatar van51 avatar yukinarit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

envclasses's Issues

Create an instance from env vars

Currently load_env function takes an instance of dataclass.

foo = Foo()
load_env(foo, ...)

This feature extends load_env to accept a class as the first argument and create an instance from env vars

foo = load_env(Foo, ...)

Use Github Action

The usage of CircleCI is still very little. I am not an expert on CicleCI, so I want to transfer my projects to using Github Action instead of CircleCI for the same purpose i.e. running tests :)

TypeError: 'ellipsis' object is not callable

I've set up a dataclass envclass, with the following attribute:

RETRIES: tuple[float, ...] = (0.1, 0.5, 2)

my .env.local file contains:

RETRIES="[1.0, 1.0]"

When I load the configuration I get:

TypeError: 'ellipsis' object is not callable
  • If i use a type tuple[float, float], this works fine.
  • If I don't add the variable in my env file, the default works fine.
  • Using parenthesis on the env variable instead of brackets did not work.
  • Also using typing.Tuple did not help.

Not sure what to do here, only workaround is a List.

Python version 3.9, envclasses 0.2.8.

Thanks for your good work.

Support Decimal

@envclass
@dataclass
class Hoge:
        d: Decimal

h = Hoge(d=Decimal(10))
os.environ['ENV_D'] = '20'

assert isinstance(h.d, Decimal)
assert h.d == Decimal(20)

Couldn't import envclasses 0.2.5

$ python
Python 3.9.6 (default, Jun 28 2021, 19:24:41)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import envclasses
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'envclasses'

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.