Skip to main content

Simple wrapper for dotenv, with casting

Project description

GitHub Actions

A simple wrapper for python-dotenv that allows for easy casting of environment strings to various data types.

Installation

Standard install:

pip install castaway

If you want Django integration (dj-email-url, dj-database-url), do:

pip install castaway[django]

Example

Easiest form is:

from castaway import config
SOME_SETTING = config('SOME_SETTING', default=None)

Like python-dotenv, this will load .env from the current working directory, or walk the parent directory tree until it is found.

For more custom usage, you can specify the exact name and path to whatever file you need. For instance, using the tests/.env file from this repo.

from datetime import datetime
from castaway import Config

config = Config('tests/.env')

CASTAWAY_INT = config('CASTAWAY_INT', cast=int)
assert CASTAWAY_INT == 23

CASTAWAY_LIST = config('CASTAWAY_LIST', cast=list)
assert CASTAWAY_LIST == ['a', 'b', 'c']

CASTAWAY_DATETIME = config('CASTAWAY_DATETIME', cast=datetime.fromisoformat)
assert CASTAWAY_DATETIME == datetime(2021, 4, 3, 14, 25)

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

castaway-0.4.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

castaway-0.4.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file castaway-0.4.0.tar.gz.

File metadata

  • Download URL: castaway-0.4.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.3

File hashes

Hashes for castaway-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a2431e80d8db195d50544d4f6d41bebe9e10e254455b2b16a6e13d5a1d4e00a4
MD5 45321196ba4d1bd21cae6dece401d887
BLAKE2b-256 4d0eb92d1af13f384bc48a051486eb8326b5dd4e76b782f89ad60c036957d6e0

See more details on using hashes here.

File details

Details for the file castaway-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: castaway-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.3

File hashes

Hashes for castaway-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7fdd9095b6946ec746ae23a8fd8b46b3c5018ce4016de6159586404028d2d88
MD5 4c67a0239d04c341f3bf74f24ddefe9f
BLAKE2b-256 97ec279a34a255ca7f6e9accab723fa38fe990a24035a597eb2be0dc1841d37d

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