Skip to main content

Environment model

Project description

EnvServ

Before starting, install dotenv

pip install python-dotenv

EnvServ - Model view for easy Python development

Example №1:

# file: .env
FirstVar = Hello, world!
SecondVar = 42
ThirdVar = 23
from envserv import EnvBase

class MyEnv(EnvBase):
    __envfile__ = '.env'

    FirstVar:str
    SecondVar:int
    ThirdVar:float

env = MyEnv()

print(env) # EnvServ(FirstVar:<class 'str'> = Hello, world!, SecondVar:<class 'int'> = 42, ThirdVar:<class 'float'> = 23.0)
print(env.FirstVar, env.SecondVar,env.ThirdVar) # Hello, world! 42 23.0
print(type(env.FirstVar), type(env.SecondVar), type(env.ThirdVar)) # <class 'str'> <class 'int'> <class 'float'>

Example №2:

from envserv import EnvBase

class MyEnv(EnvBase):
    __envfile__ = '.env'

    FirstVar:str

env = MyEnv()

env.FirstVar = "New variable value" # Also changes a variable in the .env file

print(env) # EnvServ(FirstVar:<class 'str'> = New variable value)
print(env.FirstVar) # New variable value
print(type(env.FirstVar)) # <class 'str'>

Example №3:

# file: .env
pass = 100
from envserv import EnvBase, variable

class MyEnv(EnvBase):
    __envfile__ = '.env'
    
    pass_:int = variable(alias='pass',overwrite=False)

env = MyEnv()

print(env) # EnvServ(pass_:<class 'int'> = 100)
print(env.pass_) # 100
print(type(env.pass_)) # <class 'int'>

env.pass_ = 1 # envserv.errors.EnvVariableError: Error overwriting variable pass_: It cannot be overwritten

Example №4:

# file: .env
A = Text
ERR = this is error
C = [1, 2, 3, 4, 5]
D = {1: 2, 3: 4}
E = null
F = {1,2,3,4,5}
from envserv import EnvBase, Variable

class MyEnv(EnvBase):
    __envfile__ = '.env'
    
    A:str
    B:int = Variable(alias="ERR", error=False)
    C:list
    D:dict
    E:None
    F:set
    not_in:str = "test"


env = MyEnv()
print(env.all())
print(env.all(toString=True))

# Вывод:
# {'A': 'Text', 'B': 'this is error', 'C': [1, 2, 3, 4, 5], 'D': {1: 2, 3: 4}, 'E': None, 'F': {1, 2, 3, 4, 5}, 'not_in': 'test'}
# {'A': 'Text', 'B': 'this is error', 'C': [1, 2, 3, 4, 5], 'D': {1: 2, 3: 4}, 'E': None, 'F': [1, 2, 3, 4, 5], 'not_in': 'test'}

Version logger:

1.0.0

  • Model added
  • Added variable change
  • Added class instance information output

1.0.1

  • Added rules for variable (beta)

1.0.2

  • Added setting for docker-compose (Variable __envfile__ does not need to be written)

1.0.3

  • Fix alias param
  • Fix error message

1.0.4

  • Added support for the list, dict and None variable
  • Added parameter encoding to the class instance
  • Added function all() to display the dictionary

1.0.5

  • Code refactoring has been completed
  • Added class Variable
  • Added toString parameter to all() function and added json() function

1.0.6

  • Added the ability to have a default value for .env variable
  • Fixed reading of .env file

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

envserv-1.0.6.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

envserv-1.0.6-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file envserv-1.0.6.tar.gz.

File metadata

  • Download URL: envserv-1.0.6.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for envserv-1.0.6.tar.gz
Algorithm Hash digest
SHA256 03131dd7349b98bf1059e377d2dfcaa5570edc1dbf72583cfc42125c9b9656d0
MD5 87c05ee3d9fb39402ecfe88c1d434c81
BLAKE2b-256 3f2aa39c4f50af3f6c754e54564df005ad93a89318d73c96584f222cc5974ac8

See more details on using hashes here.

File details

Details for the file envserv-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: envserv-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for envserv-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6c0305b905f34a7226b54db688370335bae95103b2dcc947188dcc293e7d517c
MD5 74b6fa501deefe1451d264d85ba77a59
BLAKE2b-256 613d3b2f3bc75d9da3a399abb384c7f1cef1b1c334c5c164d49158036c50f496

See more details on using hashes here.

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