antares-dotenv 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
antares_dotenv/core.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
from typing import Any
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
|
|
6
|
+
load_dotenv()
|
|
7
|
+
|
|
8
|
+
def _parse_value(value: str) -> Any:
|
|
9
|
+
value = value.strip()
|
|
10
|
+
|
|
11
|
+
# Boolean
|
|
12
|
+
if value.lower() in ("true", "false"):
|
|
13
|
+
return value.lower() == "true"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Integer
|
|
17
|
+
if value.isdigit():
|
|
18
|
+
return int(value)
|
|
19
|
+
|
|
20
|
+
# Float
|
|
21
|
+
try:
|
|
22
|
+
float_val = float(value)
|
|
23
|
+
return float_val
|
|
24
|
+
except ValueError:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
# JSON (The order is important: JSON first then List)
|
|
28
|
+
try:
|
|
29
|
+
return json.loads(value)
|
|
30
|
+
except (json.JSONDecodeError, TypeError):
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
# List (comma-separated)
|
|
34
|
+
if "," in value and not value.startswith("["):
|
|
35
|
+
return [_parse_value(item) for item in value.split(',')]
|
|
36
|
+
|
|
37
|
+
# Fallback to string
|
|
38
|
+
return value
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def env(key: str, default: Any = None) -> Any:
|
|
42
|
+
value = os.getenv(key)
|
|
43
|
+
if value is None:
|
|
44
|
+
return default
|
|
45
|
+
return _parse_value(value)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Antares
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: antares-dotenv
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A minimal utility to load environment variables with automatic type casting.
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Antares Mugisho
|
|
7
|
+
Author-email: antaresmugisho@gmail.com
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Requires-Dist: python-dotenv (>=1.1.0,<2.0.0)
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# My Dotenv
|
|
16
|
+
|
|
17
|
+
A minimal utility to load environment variables with automatic type casting (bool, list, int, float, JSON).
|
|
18
|
+
|
|
19
|
+
__For personnal use__
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
antares_dotenv/__init__.py,sha256=tqcxqt8bKLf1Jzmth8XH0nCpFqBdPQ5nopLHndqKlZU,41
|
|
2
|
+
antares_dotenv/core.py,sha256=exOalSTtxSLeaUGmchAd2HsRW9NsTWcevaxMUcZQohk,935
|
|
3
|
+
antares_dotenv-1.0.0.dist-info/LICENSE,sha256=ikXE-rjE8UlIQN8p47OySr--ZRxPwe9m85ZSTlWeSoo,1064
|
|
4
|
+
antares_dotenv-1.0.0.dist-info/METADATA,sha256=XNggjSjWr3rsIsjJHwC-wI_0sWDFSYqo2E4yiWw_Z18,630
|
|
5
|
+
antares_dotenv-1.0.0.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
|
|
6
|
+
antares_dotenv-1.0.0.dist-info/RECORD,,
|