envsub 0.2.0__cp313-cp313-win_amd64.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.
envsub/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """A fast and simple environment variable substitution."""
2
+
3
+ from .envsub import sub
4
+
5
+ __all__ = ["sub"]
envsub/__main__.py ADDED
@@ -0,0 +1,27 @@
1
+ """
2
+ A module executable from the shell, it read stdin, it writes std out.
3
+
4
+ ```bash
5
+ $ echo "db: ${DATABASE_URL-sqlite:///}" > config.yml
6
+ $ cat config.yml | python -m envsub
7
+ db: sqlite:///
8
+ ```
9
+ """
10
+
11
+ import sys
12
+ from .envsub import sub
13
+
14
+
15
+ def main():
16
+ cnt = 0
17
+ while True:
18
+ cnt += 1
19
+ res = sub(sys.stdin).read()
20
+ if not res:
21
+ return
22
+ else:
23
+ print(res, end="")
24
+
25
+
26
+ if __name__ == "__main__":
27
+ main()
Binary file
envsub/envsub.pyi ADDED
@@ -0,0 +1,12 @@
1
+ """Pyo3 binding interface definition."""
2
+
3
+ from typing import TextIO
4
+
5
+
6
+ def sub(downstream: TextIO) -> TextIO:
7
+ """
8
+ Replace all the envar from a downstream and return an upstream.
9
+
10
+ :downstream: A file-like object that provides text input.
11
+ :return: A file-like object with environment variables replaced.
12
+ """
envsub/py.typed ADDED
File without changes
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: envsub
3
+ Version: 0.2.0
4
+ Classifier: License :: OSI Approved :: MIT License
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Programming Language :: Rust
7
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
8
+ Classifier: Topic :: Text Processing
9
+ Classifier: Typing :: Typed
10
+ Requires-Dist: furo>=2024.5.6 ; extra == 'docs'
11
+ Requires-Dist: linkify-it-py>=2.0.3,<3 ; extra == 'docs'
12
+ Requires-Dist: myst-parser>=3.0.0,<4 ; python_full_version < '3.10' and extra == 'docs'
13
+ Requires-Dist: myst-parser>=4.0.0,<5 ; python_full_version >= '3.10' and extra == 'docs'
14
+ Requires-Dist: sphinx>=7.0.1,<8 ; extra == 'docs'
15
+ Requires-Dist: sphinx-autodoc2>=0.5.0,<1 ; extra == 'docs'
16
+ Provides-Extra: docs
17
+ License-File: LICENSE
18
+ Summary: A text preprocessing tool with environment variable substitution.
19
+ Keywords: environment,substitution,variables
20
+ Author: Guillaume Gauvrit <guillaume@gauvr.it>
21
+ Author-email: Guillaume Gauvrit <guillaume@gauvr.it>
22
+ License: MIT License
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
25
+ Project-URL: Homepage, https://mardiros.github.io/envsub/
26
+ Project-URL: Documentation, https://mardiros.github.io/mardiros/envsub
27
+ Project-URL: Repository, https://github.com/mardiros/envsub.git
28
+ Project-URL: Issues, https://github.com/mardiros/envsub/issues
29
+ Project-URL: Changelog, https://mardiros.github.io/mardiros/envsub/changelog.html
30
+
31
+ # envsub
32
+
33
+ [![Documentation](https://github.com/mardiros/envsub/actions/workflows/publish-doc.yml/badge.svg)](https://mardiros.github.io/envsub/)
34
+ [![Continuous Integration](https://github.com/mardiros/envsub/actions/workflows/tests.yml/badge.svg)](https://github.com/mardiros/envsub/actions/workflows/tests.yml)
35
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a63ad49239e41de4f6b7/maintainability)](https://codeclimate.com/github/mardiros/envsub/maintainability)
36
+
37
+ **envsub** is a text preprocessing tool that performs environment variable
38
+ substitution in files, with support for default values. Written in Rust and
39
+ callable from Python, it provides a fast and reliable way to inject environment
40
+ variables into text files during runtime.
41
+
42
+ ## Features
43
+
44
+ - Environment variable substitution in any text file.
45
+ - Support for default values when environment variables are missing.
46
+ - Fast performance with Rust under the hood, accessible from Python.
47
+
48
+ ## Installation
49
+
50
+ ```bash
51
+ pip install envsub
52
+ ```
53
+
54
+
55
+ ## Usage
56
+
57
+
58
+ ### envsub api
59
+
60
+ envsub comes with a `sub` method that text a `io.TextIO` and return
61
+ a `io.TextIO` containing the replaced variable.
62
+
63
+ Basic usage:
64
+
65
+ ```python
66
+ from envsub import sub
67
+
68
+
69
+ with open("/path/to/file", "r") as downstream:
70
+ with sub(downstream) as upstream:
71
+ upstream.read()
72
+
73
+ ```
74
+
75
+
76
+ When it is usefull.
77
+
78
+ ``envsub`` is made for replacing a set of variable inside a configuration
79
+ file from envisonment variable, its feet well with confifuration file format.
80
+
81
+ Example with json:
82
+
83
+
84
+ ```python
85
+ import json
86
+ from envsub import sub
87
+
88
+ with open("/path/to/file.json", "r") as downstream:
89
+ with sub(downstream) as upstream:
90
+ data = json.load(upstream)
91
+
92
+ ```
93
+
94
+
95
+ ### Substitution format
96
+
97
+ envsubst subsitute variable format that are curly-braced, like in bash.
98
+
99
+ ```json
100
+ {"hello": "${NAME}"}
101
+ ```
102
+
103
+ > ⚠️ **Warning:**
104
+ >
105
+ > The variable stay in the same line, no `\n` are permitted.**
106
+ >
107
+ > This will **not** work:
108
+ > {"hello": "${
109
+ > NAME
110
+ > }"
111
+ > }
112
+ >
113
+
114
+
115
+ #### Default value:
116
+
117
+ If the environment variable is not present, no substitution will be made,
118
+ it means than in the previous example, `${NAME}` will stay in the read value.
119
+
120
+ Alternatively, a default value can be set in the variable, using a `-` value.
121
+
122
+
123
+ ```json
124
+ {"hello": "${NAME-world}"}
125
+ ```
126
+
127
+ In this case the final result will be `{"hello": "world"}`.
128
+
129
+
130
+
131
+ ## Alternatives
132
+
133
+ Similar tools exists, but did not find any good one in python.
134
+
135
+ The envsub lib has been created to replace non existing tool like
136
+ [a8m/envsubst](https://github.com/a8m/envsubst) a Go binary that
137
+ update the GNU envsubst that do not support default values.
138
+
@@ -0,0 +1,10 @@
1
+ envsub-0.2.0.dist-info/METADATA,sha256=taQmisa0xpWEXwZDCZmx9GDCH_bxDaZtp-C96nmgqDs,4146
2
+ envsub-0.2.0.dist-info/WHEEL,sha256=XsgF4V7TnSmJTnuU62xP5hrnZJ48WDEWrpRztgXGPlM,96
3
+ envsub-0.2.0.dist-info/entry_points.txt,sha256=g12l_7WuetC36PiIyzLD2yY0bMu0WGCwrgUbRga0YdY,36
4
+ envsub-0.2.0.dist-info/licenses/LICENSE,sha256=D_2CSBqhb-ro_uhPo0uQgF_93O8-hhN3L6oDWfbsa-c,1101
5
+ envsub/envsub.pyi,sha256=Gyes_TF_20u2dtefaPQ-FW91XXFw0Jb3RlBRruPla4k,337
6
+ envsub/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ envsub/__init__.py,sha256=yDqf0SKSFCQlj8HQ0eaTL6ShdC4cWGKjV78eVZUUYeY,108
8
+ envsub/__main__.py,sha256=_o1j9NjjlDSKjjEL84wms6G1EZKiB3UXC53-uScDbbg,477
9
+ envsub/envsub.cp313-win_amd64.pyd,sha256=e3pjJLikYq9qLzzNhiZ_VjUPz6BbkFelW0tp4eABoNk,283648
10
+ envsub-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.8.2)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ envsub=envsub:sub
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2025, Guillaume Gauvrit
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.