Skip to main content

Typed dotenv parser

Project description

Getting Started

Use pip install parsenv.

Reads .env file on import, then reads other env-files from $ENVPATH (comma separated).

Example

import env

assert env.get("TOKEN") == "abc123"
assert env.get("X", None) is None
assert env.get_int("PORT") == 123
assert env.get_strs("KEYS", []) == ["word1", "F402", "12"]
assert env.get_ints("ADMIN_IDS") == [1, 2, 3]
assert env.get_ints("X", [0]) == [0]

with env.prefix("BOOL"):
    assert env.get_bool("T")
    assert not env.get_bool("F")

try:
    env.get("X")
except Exception as e:
    assert str(e) == 'Mandatory environment variable "X" is missing'

try:
    env.get_ints("BAD_NUMS")
except Exception as e:
    assert str(e) == 'Failed to cast "1,2,a" (variable name "BAD_NUMS") to list'

try:
    env.get_bool("BAD_BOOL")
except Exception as e:
    assert str(e) == 'Failed to cast "ok" (variable name "BAD_BOOL") to bool'

assert env.raw.float("FLOAT") == 1.45

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

parsenv-0.3.0.tar.gz (1.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parsenv-0.3.0-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file parsenv-0.3.0.tar.gz.

File metadata

  • Download URL: parsenv-0.3.0.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.5.3 CPython/3.10.5

File hashes

Hashes for parsenv-0.3.0.tar.gz
Algorithm Hash digest
SHA256 396380632f993f2325f3cf593187ef873267bab7afaa7a2b309d218e692c7bf1
MD5 13e78d5c8459d4d66227543c9a2d7cce
BLAKE2b-256 6101c10010e0f2b0f74169673cc57595142d72409d33ffadd96700ac9a9c0a95

See more details on using hashes here.

File details

Details for the file parsenv-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: parsenv-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 2.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.5.3 CPython/3.10.5

File hashes

Hashes for parsenv-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4d6d2941c41474a83171cb9e4a7611cb022b7159eb7c2d011176050bb058728
MD5 a30e406c7c8770908b27d811c356afcd
BLAKE2b-256 1780f9a42a3a994a488328b61cb45b67b606c685de2d5c6a171877d5dee65c67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page