You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

enviparse

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enviparse

enviparse help you manage your application properties using environment variabl

2.0.1
Source
pipPyPI
Maintainers
1

Enviparse

CI codecov

Description

Enviparse let you simply create dataclasses from environment variable.

Supported types are :

  • int
  • float
  • str
  • bool
  • optional
  • list
  • enum (with int or string values only)
  • @attr annotated class
  • @dataclasses.dataclass annotated class

Example

With following environment variables :

DATABASE_CONFIG_USERNAME=postgres
DATABASE_CONFIG_PASSWORD=password
DATABASE_CONFIG_HOST=127.0.0.1
DATABASE_CONFIG_PORT=5432
DATABASE_CONFIG_DATABASE_NAME=appdb

You can parse environment variable with :

import dataclasses
from enviparse import Enviparse


@dataclasses.dataclass
class DatabaseConfig:
    username: str
    password: str
    host: str
    port: int
    database_name: str


db_config = Enviparse().parse("DATABASE_CONFIG", DatabaseConfig)
print(db_config)

You should get the following result :

DatabaseConfig(username='postgres', password='password', host='127.0.0.1', port=5432, database_name='appdb')

For more example see the test folder.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts