Metadata-Version: 2.2
Name: castaway
Version: 1.1.0
Summary: Simple wrapper for dotenv, with casting
Author-email: David Krauth <dakrauth@gmail.com>
License: MIT License
        
        Copyright (c) 2025 David A Krauth
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, http://github.com/dakrauth/castaway
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Environment :: Console
Classifier: Framework :: Django
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: python-dotenv[cli]==1.0.1
Provides-Extra: django
Requires-Dist: dj-email-url==1.0.6; extra == "django"
Requires-Dist: dj-database-url==2.3.0; extra == "django"
Provides-Extra: test
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: tox; extra == "test"

castaway
========

.. image:: https://github.com/dakrauth/castaway/workflows/Test/badge.svg
   :target: https://github.com/dakrauth/castaway/actions
   :alt: GitHub Actions

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

.. _python-dotenv: https://pypi.org/project/python-dotenv/

Installation
------------

Standard install:

.. code::

    pip install castaway


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

.. code::

    pip install castaway[django]


Example
-------

Easiest form is:

.. code:: python

    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.

.. code:: python

    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)
