appsettings2 2.0.9__tar.gz → 2.0.10__tar.gz

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.
Files changed (24) hide show
  1. {appsettings2-2.0.9/src/appsettings2.egg-info → appsettings2-2.0.10}/PKG-INFO +2 -2
  2. {appsettings2-2.0.9 → appsettings2-2.0.10}/pyproject.toml +2 -2
  3. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/ConfigurationBuilder.py +3 -2
  4. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/__init__.py +2 -2
  5. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/helpers.py +13 -2
  6. appsettings2-2.0.10/src/appsettings2/providers/EnvironmentConfigurationProvider.py +43 -0
  7. {appsettings2-2.0.9 → appsettings2-2.0.10/src/appsettings2.egg-info}/PKG-INFO +2 -2
  8. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2.egg-info/requires.txt +1 -1
  9. appsettings2-2.0.9/src/appsettings2/providers/EnvironmentConfigurationProvider.py +0 -14
  10. {appsettings2-2.0.9 → appsettings2-2.0.10}/LICENSE +0 -0
  11. {appsettings2-2.0.9 → appsettings2-2.0.10}/README.md +0 -0
  12. {appsettings2-2.0.9 → appsettings2-2.0.10}/setup.cfg +0 -0
  13. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/Configuration.py +0 -0
  14. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/ConfigurationException.py +0 -0
  15. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/providers/CommandLineConfigurationProvider.py +0 -0
  16. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/providers/ConfigurationProvider.py +0 -0
  17. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/providers/JsonConfigurationProvider.py +0 -0
  18. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/providers/TomlConfigurationProvider.py +0 -0
  19. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/providers/YamlConfigurationProvider.py +0 -0
  20. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/providers/__init__.py +0 -0
  21. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2/py.typed +0 -0
  22. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2.egg-info/SOURCES.txt +0 -0
  23. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2.egg-info/dependency_links.txt +0 -0
  24. {appsettings2-2.0.9 → appsettings2-2.0.10}/src/appsettings2.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: appsettings2
3
- Version: 2.0.9
3
+ Version: 2.0.10
4
4
  Summary: Unifies configuration sources into a Configuration object that can be bound to complex types, or accessed directly for configuration data.
5
5
  Author-email: Shaun Wilson <mrshaunwilson@msn.com>
6
6
  License: MIT License
@@ -42,7 +42,7 @@ Requires-Dist: flake8; extra == "dev"
42
42
  Requires-Dist: flake8-pyproject; extra == "dev"
43
43
  Requires-Dist: mypy; extra == "dev"
44
44
  Requires-Dist: pep8-naming; extra == "dev"
45
- Requires-Dist: punit>=1.4.9; extra == "dev"
45
+ Requires-Dist: punit>=1.10.8; extra == "dev"
46
46
  Requires-Dist: twine; extra == "dev"
47
47
  Requires-Dist: types-PyYAML; extra == "dev"
48
48
  Dynamic: license-file
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "appsettings2"
3
- version = "2.0.9"
3
+ version = "2.0.10"
4
4
  description = "Unifies configuration sources into a Configuration object that can be bound to complex types, or accessed directly for configuration data."
5
5
  keywords = ["appsettings", "configuration"]
6
6
  authors = [
@@ -25,7 +25,7 @@ dev = [
25
25
  "flake8-pyproject",
26
26
  "mypy",
27
27
  "pep8-naming",
28
- "punit (>=1.4.9)",
28
+ "punit (>=1.10.8)",
29
29
  "twine",
30
30
  "types-PyYAML"
31
31
  ]
@@ -65,13 +65,14 @@ class ConfigurationBuilder:
65
65
  addCommandLine = add_command_line
66
66
  """⚠️ DEPRECATED: use ``add_command_line(...)`` instead."""
67
67
 
68
- def add_environment(self) -> 'ConfigurationBuilder':
68
+ def add_environment(self, required_prefix: str | None = None) -> 'ConfigurationBuilder':
69
69
  """
70
70
  Add a :py:class:`~appsettings2.providers.EnvironmentConfigurationProvider`.
71
71
 
72
+ :param required_prefix: Optional prefix used to filter which environment variables are included. Only variables whose names start with this prefix (followed by ``_`` or ``__``) will be loaded. When ``None``, all environment variables are included. Defaults to None.
72
73
  :return: Returns :py:class:`~appsettings2.ConfigurationBuilder` for method chaining.
73
74
  """
74
- return self.add_provider(EnvironmentConfigurationProvider())
75
+ return self.add_provider(EnvironmentConfigurationProvider(required_prefix=required_prefix))
75
76
 
76
77
  addEnvironment = add_environment
77
78
  """⚠️ DEPRECATED: use ``add_environment(...)`` instead."""
@@ -10,8 +10,8 @@ from . import helpers
10
10
  from . import providers
11
11
 
12
12
 
13
- __version__ = '2.0.9'
14
- __commit__ = 'b510516'
13
+ __version__ = '2.0.10'
14
+ __commit__ = 'fe8eec3'
15
15
  __all__ = [
16
16
  '__version__', '__commit__',
17
17
  'Configuration',
@@ -8,7 +8,17 @@ from .Configuration import Configuration
8
8
  from .ConfigurationBuilder import ConfigurationBuilder
9
9
 
10
10
 
11
- def get_configuration(basename: str | pathlib.PosixPath | pathlib.Path = 'appsettings', json: bool = True, toml: bool = True, yaml: bool = True, cli: bool = True, environment: bool = True, variations: Optional[list[str | None]] = ['', 'prod', 'production', 'stage', 'staging', 'qa', 'dev', 'development', 'local']) -> Configuration:
11
+ def get_configuration(
12
+ basename: str | pathlib.PosixPath | pathlib.Path = 'appsettings',
13
+ *,
14
+ json: bool = True,
15
+ toml: bool = True,
16
+ yaml: bool = True,
17
+ cli: bool = True,
18
+ environment: bool = True,
19
+ variations: Optional[list[str | None]] = ['', 'prod', 'production', 'stage', 'staging', 'qa', 'dev', 'development', 'local'],
20
+ env_prefix: str | None = None
21
+ ) -> Configuration:
12
22
  """
13
23
  Get a ``Configuration`` instance by loading from a set of well-known providers and their variations.
14
24
 
@@ -19,6 +29,7 @@ def get_configuration(basename: str | pathlib.PosixPath | pathlib.Path = 'appset
19
29
  :param cli: ``True`` to load configuration from Command-Line, defaults to True
20
30
  :param environment: ``True`` to load configuration from process Environment, defaults to True
21
31
  :param variations: A set of variations to apply to use with file-based Configuration Providers, defaults to ['', 'prod', 'production', 'stage', 'staging', 'qa', 'dev', 'development', 'local']
32
+ :param env_prefix: (OPTIONAL) When specified, only env vars having the specified prefix are bound as configuration settings, the prefix is stripped from the resulting setting name.
22
33
  :return: An ``appsettings2.Configuration`` instance.
23
34
  """
24
35
  if type(basename) is pathlib.Path or type(basename) is pathlib.PosixPath:
@@ -36,7 +47,7 @@ def get_configuration(basename: str | pathlib.PosixPath | pathlib.Path = 'appset
36
47
  if cli:
37
48
  builder.add_command_line()
38
49
  if environment:
39
- builder.add_environment()
50
+ builder.add_environment(required_prefix=env_prefix)
40
51
  return builder.build()
41
52
 
42
53
 
@@ -0,0 +1,43 @@
1
+ # SPDX-FileCopyrightText: © 2025 Shaun Wilson
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ import os
5
+ from typing import Any
6
+
7
+ from ..Configuration import Configuration
8
+ from .ConfigurationProvider import ConfigurationProvider
9
+
10
+
11
+ class EnvironmentConfigurationProvider(ConfigurationProvider):
12
+ """A ``ConfigurationProvider`` that populates configuration data from Environment variables."""
13
+
14
+ __required_prefix: str | None
15
+
16
+ def __init__(self, /, required_prefix: str | None = None, **kwargs: Any) -> None:
17
+ self.__required_prefix = required_prefix.upper() if required_prefix is not None else None
18
+
19
+ def populate_configuration(self, configuration: Configuration) -> None:
20
+ """
21
+ Populate the provided :py:class:`~appsettings2.Configuration` from environment variables.
22
+
23
+ Usage::
24
+
25
+ # All env vars become config keys:
26
+ provider = EnvironmentConfigurationProvider()
27
+ provider.populate_configuration(config)
28
+
29
+ # Only keys with a specific prefix, stripped in output:
30
+ provider = EnvironmentConfigurationProvider(required_prefix="APP_")
31
+ # APP_DATABASE_URL=postgres://... → config["DATABASE_URL"] == "postgres://..."
32
+ provider.populate_configuration(config)
33
+
34
+ When ``required_prefix`` is set, only keys starting with that prefix are included,
35
+ and the prefix is stripped from each key in the output configuration.
36
+ """
37
+ for k in os.environ:
38
+ key = (
39
+ k
40
+ if self.__required_prefix is None
41
+ else k[len(self.__required_prefix):]
42
+ )
43
+ configuration.set(key, os.environ[k])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: appsettings2
3
- Version: 2.0.9
3
+ Version: 2.0.10
4
4
  Summary: Unifies configuration sources into a Configuration object that can be bound to complex types, or accessed directly for configuration data.
5
5
  Author-email: Shaun Wilson <mrshaunwilson@msn.com>
6
6
  License: MIT License
@@ -42,7 +42,7 @@ Requires-Dist: flake8; extra == "dev"
42
42
  Requires-Dist: flake8-pyproject; extra == "dev"
43
43
  Requires-Dist: mypy; extra == "dev"
44
44
  Requires-Dist: pep8-naming; extra == "dev"
45
- Requires-Dist: punit>=1.4.9; extra == "dev"
45
+ Requires-Dist: punit>=1.10.8; extra == "dev"
46
46
  Requires-Dist: twine; extra == "dev"
47
47
  Requires-Dist: types-PyYAML; extra == "dev"
48
48
  Dynamic: license-file
@@ -6,6 +6,6 @@ flake8
6
6
  flake8-pyproject
7
7
  mypy
8
8
  pep8-naming
9
- punit>=1.4.9
9
+ punit>=1.10.8
10
10
  twine
11
11
  types-PyYAML
@@ -1,14 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 Shaun Wilson
2
- # SPDX-License-Identifier: MIT
3
-
4
- from .ConfigurationProvider import ConfigurationProvider
5
- from ..Configuration import Configuration
6
- import os
7
-
8
-
9
- class EnvironmentConfigurationProvider(ConfigurationProvider):
10
- """A ``ConfigurationProvider`` that populates configuration data from Environment variables."""
11
-
12
- def populate_configuration(self, configuration: Configuration) -> None: # noqa: D102
13
- for k in os.environ:
14
- configuration.set(k, os.environ[k])
File without changes
File without changes
File without changes