python-simpleconf 0.9.5__py3-none-any.whl → 0.9.7__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: python-simpleconf
3
- Version: 0.9.5
3
+ Version: 0.9.7
4
4
  Summary: Simple configuration management with python.
5
5
  Project-URL: Homepage, https://github.com/pwwang/simpleconf
6
6
  Project-URL: Repository, https://github.com/pwwang/simpleconf
@@ -14,7 +14,8 @@ Provides-Extra: all
14
14
  Requires-Dist: iniconfig<3,>=2.0; extra == 'all'
15
15
  Requires-Dist: python-dotenv<2,>=1.1; extra == 'all'
16
16
  Requires-Dist: pyyaml<7,>=6; extra == 'all'
17
- Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux') and extra == 'all'
17
+ Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux' and python_version < '3.10') and extra == 'all'
18
+ Requires-Dist: rtoml<1,>=0.12; (sys_platform == 'linux' and python_version >= '3.10') and extra == 'all'
18
19
  Requires-Dist: tomli<3,>=2.0; (sys_platform != 'linux') and extra == 'all'
19
20
  Provides-Extra: async
20
21
  Requires-Dist: aiofiles>=23.0.0; extra == 'async'
@@ -29,7 +30,8 @@ Requires-Dist: liquidpy<0.9,>=0.8; extra == 'liquid'
29
30
  Provides-Extra: liquidpy
30
31
  Requires-Dist: liquidpy<0.9,>=0.8; extra == 'liquidpy'
31
32
  Provides-Extra: toml
32
- Requires-Dist: rtoml<1,>=0.12; (sys_platform == 'linux') and extra == 'toml'
33
+ Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux' and python_version < '3.10') and extra == 'toml'
34
+ Requires-Dist: rtoml<1,>=0.12; (sys_platform == 'linux' and python_version >= '3.10') and extra == 'toml'
33
35
  Requires-Dist: tomli<3,>=2.0; (sys_platform != 'linux') and extra == 'toml'
34
36
  Provides-Extra: yaml
35
37
  Requires-Dist: pyyaml<7,>=6; extra == 'yaml'
@@ -37,7 +39,12 @@ Description-Content-Type: text/markdown
37
39
 
38
40
  # simpleconf
39
41
 
40
- Simple configuration management for python
42
+ <div align="center">
43
+ <img src="./docs/logo.png" width="220px" alt="python-simpleconf logo" />
44
+
45
+ <p style="font-weight:bold;">Simple configuration management for Python</p>
46
+
47
+ </div>
41
48
 
42
49
  ## Installation
43
50
  ```shell
@@ -467,6 +474,9 @@ The `$env:` syntax supports optional modifiers to control the behavior when a va
467
474
  | `$env:VAR:required` | Explicit form — raises `ValueError` |
468
475
  | `$env:VAR:optional-asis` | Keeps the literal `$env:VAR` string unchanged |
469
476
  | `$env:VAR:optional-empty` | Resolves to an empty string `""` |
477
+ | `$env:VAR:default:<value>` | Resolves to `<value>` instead |
478
+
479
+ When found, the environment variable's value always wins over the `default`. Default values go through the same casting as env values, so cast prefixes like `@int:` work there too (e.g. `$env:PORT:default:@int:8080` resolves to the integer `8080`). The default value itself may contain colons (e.g. `$env:URL:default:http://localhost:8080`).
470
480
 
471
481
  **Example — using modifiers:**
472
482
 
@@ -482,6 +492,7 @@ db:
482
492
  host: $env:DB_HOST
483
493
  port: $env:DB_PORT:optional-asis # keeps "$env:DB_PORT" as-is when not found
484
494
  timeout: $env:TIMEOUT:optional-empty # becomes "" when not found
495
+ user: $env:DB_USER:default:admin # becomes "admin" when not found
485
496
  ```
486
497
 
487
498
  ```python
@@ -491,6 +502,7 @@ conf = Config.load('config.yaml')
491
502
  # conf.db.host == 'localhost'
492
503
  # conf.db.port == '$env:DB_PORT'
493
504
  # conf.db.timeout == ''
505
+ # conf.db.user == 'admin'
494
506
  ```
495
507
 
496
508
  **Example — using `env` in templates:**
@@ -1,10 +1,10 @@
1
- simpleconf/__init__.py,sha256=wrkpYialYF4KkMHvjDPalFW7VZOusyaCU7iGDEa6Gc8,104
1
+ simpleconf/__init__.py,sha256=g0YV1X3rEqWAWJt31pgJiia31Tv_GMJhx5oXx68B9cA,104
2
2
  simpleconf/caster.py,sha256=qHnegp1FZzbUWm-UbCaGjQKN6d9rN1v_0Wa4I_CMEi4,2379
3
3
  simpleconf/config.py,sha256=Wf6zCoUs3QGHVFdYTFldcIVk6vmmqnf9bth4Wz0F2Lw,18677
4
4
  simpleconf/exceptions.py,sha256=Tb7w9gMO2XU4mE-Rc2HAnuHWDUpMzdl39oGVjeAv254,171
5
5
  simpleconf/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  simpleconf/utils.py,sha256=JXnmdGd3JE6QDPvL9QSQi_lC07vQLDuIbof6b4idEIA,8856
7
- simpleconf/loaders/__init__.py,sha256=ZuWgb_D8UUwniWKltg7jtjAhEUm0J6sCZrFkXVSSweM,8491
7
+ simpleconf/loaders/__init__.py,sha256=GTWb6Iq1C9YYd_Jb8QgtI3hM-1bLVA4H6jawIRfZ95c,9202
8
8
  simpleconf/loaders/dict.py,sha256=8Az511i9OLLXosSBMMXiEfiQVScQ5SIqsF6EHlAkKdM,801
9
9
  simpleconf/loaders/env.py,sha256=cOYZbHk08MrBjxtNfV8Cv5LHrZg_flzap1lOM3GVdRk,3729
10
10
  simpleconf/loaders/ini.py,sha256=a8ahJIzw24SIEnGbZmYNoxo8O1tYi6pG_GrOil0Rcx0,3739
@@ -12,7 +12,7 @@ simpleconf/loaders/json.py,sha256=0NTKB9JidB8vbeODxNYAY8fJP6__znetuIUAClFeNIo,19
12
12
  simpleconf/loaders/osenv.py,sha256=K829KFiHLl3pS8HSCep8JoPVG_d7VRxPAb7SPYFRypg,1779
13
13
  simpleconf/loaders/toml.py,sha256=OJCukg_R3zlmas_q_CrdeKUsw8Wj5LoSnkNJ7Flt86w,2525
14
14
  simpleconf/loaders/yaml.py,sha256=IoKMaQF5y5HWEjQsnUwL2UvABVj9A-0AmBhn8s7lE54,2146
15
- python_simpleconf-0.9.5.dist-info/METADATA,sha256=7Nj2Ku_RsdJGLpeReGByUurGdh9-dp6eF_yVDQfaBOo,11876
16
- python_simpleconf-0.9.5.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
17
- python_simpleconf-0.9.5.dist-info/licenses/LICENSE,sha256=2j7OLS2vXIEshgbSkiCU9RgYJY1M4OBBtO6ECbo7OB8,1056
18
- python_simpleconf-0.9.5.dist-info/RECORD,,
15
+ python_simpleconf-0.9.7.dist-info/METADATA,sha256=CoLmwMMkmUtmLJFcRdJiGUCojJacScydovzYqT0i_YA,12791
16
+ python_simpleconf-0.9.7.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
17
+ python_simpleconf-0.9.7.dist-info/licenses/LICENSE,sha256=2j7OLS2vXIEshgbSkiCU9RgYJY1M4OBBtO6ECbo7OB8,1056
18
+ python_simpleconf-0.9.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.31.0
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
simpleconf/__init__.py CHANGED
@@ -2,4 +2,4 @@ from .config import Config, ProfileConfig
2
2
 
3
3
  __all__ = ["Config", "ProfileConfig"]
4
4
 
5
- __version__ = "0.9.5"
5
+ __version__ = "0.9.7"
@@ -73,6 +73,10 @@ class Loader(ABC):
73
73
  1. ``self.env_vars`` (loaded from ``.env`` file via directive)
74
74
  2. ``os.environ`` (system environment variables)
75
75
 
76
+ ``$env:KEY:default:<value>`` falls back to ``<value>`` when the
77
+ variable is not found (modifiers ``required``, ``optional-asis`` and
78
+ ``optional-empty`` control the not-found behavior otherwise).
79
+
76
80
  Resolved values are re-cast through :attr:`CASTERS`.
77
81
 
78
82
  Returns the mutated Diot for chaining.
@@ -90,7 +94,13 @@ class Loader(ABC):
90
94
  return value
91
95
  if isinstance(value, str) and value.startswith("$env:"):
92
96
  rest = value[5:]
93
- if ":" in rest:
97
+ default = None
98
+ if ":default:" in rest:
99
+ # $env:VAR:default:<value> — split on first occurrence so
100
+ # the default itself may contain colons
101
+ var_name, _, default = rest.partition(":default:")
102
+ modifier = "required"
103
+ elif ":" in rest:
94
104
  var_name, modifier = rest.rsplit(":", 1)
95
105
  if modifier not in KNOWN_MODIFIERS:
96
106
  # Unknown modifier — treat whole string as var name
@@ -105,6 +115,10 @@ class Loader(ABC):
105
115
  if resolved is not None:
106
116
  return cast_value(resolved, _ENV_CASTERS)
107
117
 
118
+ # Not found — use the default value if given
119
+ if default is not None:
120
+ return cast_value(default, _ENV_CASTERS)
121
+
108
122
  # Not found — behavior depends on modifier
109
123
  if modifier == "optional-empty":
110
124
  return ""