Simple wrapper for dotenv, with casting
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
castaway-1.0.0.tar.gz
(4.4 kB
view details)
Built Distribution
File details
Details for the file castaway-1.0.0.tar.gz
.
File metadata
- Download URL: castaway-1.0.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b798b64831a601029a7fb443301f6b9f02a65a4c2d07103034d22522654aacf |
|
MD5 | 9963274d4d1fdb21e0b583d436b9309b |
|
BLAKE2b-256 | 8bf9fcd8e1193ed3911a8b85d832fd4e77555e573310d9fe8082444088ac3985 |
File details
Details for the file castaway-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: castaway-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 996ebaa96e7c740a50ed83f9a3eed9233602a01a474501d09d7d8e093c51cdc8 |
|
MD5 | 91a05a17caf06b5c3c3afbac20435184 |
|
BLAKE2b-256 | b613e25ca5b3a9b80bfd973ca447ce4e9c17e4e6fbd89d0926588ea0219c0680 |