envdot 1.0.0__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.
@@ -0,0 +1,6 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ recursive-include envdot *.py
5
+ recursive-exclude * __pycache__
6
+ recursive-exclude * *.py[co]
envdot-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,331 @@
1
+ Metadata-Version: 2.4
2
+ Name: envdot
3
+ Version: 1.0.0
4
+ Summary: Enhanced environment variable management with multi-format support
5
+ Home-page: https://github.com/cumulus13/envdot
6
+ Author: Hadi Cahyadi
7
+ Author-email: Hadi Cahyadi <cumulus13@gmail.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/cumulus13/envdot
10
+ Project-URL: Documentation, https://github.com/cumulus13/envdot#readme
11
+ Project-URL: Repository, https://github.com/cumulus13/envdot
12
+ Project-URL: Bug Tracker, https://github.com/cumulus13/envdot/issues
13
+ Keywords: environment,variables,config,envdot,configuration
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.7
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Requires-Python: >=3.7
26
+ Description-Content-Type: text/markdown
27
+ Provides-Extra: yaml
28
+ Requires-Dist: PyYAML>=5.1; extra == "yaml"
29
+ Provides-Extra: all
30
+ Requires-Dist: PyYAML>=5.1; extra == "all"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
34
+ Requires-Dist: black>=22.0.0; extra == "dev"
35
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
36
+ Requires-Dist: mypy>=0.950; extra == "dev"
37
+ Dynamic: author
38
+ Dynamic: home-page
39
+ Dynamic: requires-python
40
+
41
+ # envdot
42
+
43
+ Enhanced environment variable management for Python with multi-format support and automatic type detection.
44
+
45
+ ## Features
46
+
47
+ - 🔧 **Multiple Format Support**: `.env`, `.json`, `.yaml`, `.yml`, and `.ini` files
48
+ - 🎯 **Automatic Type Detection**: Automatically converts strings to `bool`, `int`, `float`, or keeps as `string`
49
+ - 💾 **Read and Write**: Load from and save to configuration files
50
+ - 🔄 **Method Chaining**: Fluent API for cleaner code
51
+ - 🌍 **OS Environment Integration**: Seamlessly works with `os.environ`
52
+ - 📦 **Zero Dependencies**: Core functionality works without external packages (YAML support requires PyYAML)
53
+
54
+ ## Installation
55
+
56
+ ```bash
57
+ pip install envdot
58
+
59
+ # With YAML support
60
+ pip install envdot[yaml]
61
+
62
+ # With all extras
63
+ pip install envdot[all]
64
+ ```
65
+
66
+ ## Quick Start
67
+
68
+ ### Basic Usage
69
+
70
+ ```python
71
+ from envdot import DotEnv
72
+
73
+ # Auto-detect and load from common config files (.env, config.json, etc.)
74
+ env = DotEnv()
75
+
76
+ # Or specify a file
77
+ env = DotEnv('.env')
78
+
79
+ # Get values with automatic type detection
80
+ db_host = env.get('DB_HOST') # Returns string
81
+ db_port = env.get('DB_PORT') # Returns int (auto-detected)
82
+ debug_mode = env.get('DEBUG') # Returns bool (auto-detected)
83
+ api_timeout = env.get('API_TIMEOUT') # Returns float (auto-detected)
84
+
85
+ # Set values
86
+ env.set('NEW_KEY', 'value')
87
+ env.set('FEATURE_ENABLED', True)
88
+
89
+ # Save to file
90
+ env.save('.env')
91
+ ```
92
+
93
+ ### Convenience Functions
94
+
95
+ ```python
96
+ from envdot import load_env, get_env, set_env, save_env
97
+
98
+ # Load configuration
99
+ load_env('.env')
100
+
101
+ # Get values
102
+ database_url = get_env('DATABASE_URL')
103
+ max_connections = get_env('MAX_CONNECTIONS', default=100)
104
+
105
+ # Set values
106
+ set_env('NEW_FEATURE', True)
107
+
108
+ # Save changes
109
+ save_env('.env')
110
+ ```
111
+
112
+ ### Working with Different File Formats
113
+
114
+ #### .env File
115
+ ```python
116
+ env = DotEnv('.env')
117
+ env.load()
118
+ ```
119
+
120
+ #### JSON File
121
+ ```python
122
+ env = DotEnv('config.json')
123
+ env.load()
124
+ ```
125
+
126
+ #### YAML File
127
+ ```python
128
+ env = DotEnv('config.yaml')
129
+ env.load() # Requires PyYAML
130
+ ```
131
+
132
+ #### INI File
133
+ ```python
134
+ env = DotEnv('config.ini')
135
+ env.load()
136
+ ```
137
+
138
+ ### Type Detection Examples
139
+
140
+ The package automatically detects and converts types:
141
+
142
+ ```python
143
+ # Given this .env file:
144
+ # DEBUG=true
145
+ # PORT=8080
146
+ # TIMEOUT=30.5
147
+ # APP_NAME=MyApp
148
+ # EMPTY_VALUE=
149
+
150
+ env = DotEnv('.env')
151
+
152
+ env.get('DEBUG') # Returns: True (bool)
153
+ env.get('PORT') # Returns: 8080 (int)
154
+ env.get('TIMEOUT') # Returns: 30.5 (float)
155
+ env.get('APP_NAME') # Returns: 'MyApp' (str)
156
+ env.get('EMPTY_VALUE') # Returns: None
157
+ ```
158
+
159
+ ### Explicit Type Casting
160
+
161
+ ```python
162
+ # Force a specific type
163
+ version = env.get('VERSION', cast_type=str)
164
+ port = env.get('PORT', cast_type=int)
165
+ enabled = env.get('ENABLED', cast_type=bool)
166
+ ```
167
+
168
+ ### Method Chaining
169
+
170
+ ```python
171
+ env = DotEnv('.env') \
172
+ .load() \
173
+ .set('NEW_KEY', 'value') \
174
+ .set('ANOTHER_KEY', 123) \
175
+ .save()
176
+ ```
177
+
178
+ ### Dictionary-Style Access
179
+
180
+ ```python
181
+ env = DotEnv('.env')
182
+
183
+ # Get values
184
+ value = env['KEY_NAME']
185
+
186
+ # Set values
187
+ env['NEW_KEY'] = 'new value'
188
+
189
+ # Check existence
190
+ if 'API_KEY' in env:
191
+ print("API key is configured")
192
+
193
+ # Get all variables
194
+ all_vars = env.all()
195
+ ```
196
+
197
+ ### Advanced Features
198
+
199
+ #### Load Without Overriding
200
+
201
+ ```python
202
+ env.load(override=False) # Keep existing values
203
+ ```
204
+
205
+ #### Load Without Applying to OS Environment
206
+
207
+ ```python
208
+ env.load(apply_to_os=False) # Don't set in os.environ
209
+ ```
210
+
211
+ #### Save to Different Format
212
+
213
+ ```python
214
+ env = DotEnv('.env')
215
+ env.load()
216
+ env.save('config.json') # Convert .env to JSON
217
+ ```
218
+
219
+ #### Clear Variables
220
+
221
+ ```python
222
+ env.clear() # Clear internal storage only
223
+ env.clear(clear_os=True) # Also clear from os.environ
224
+ ```
225
+
226
+ #### Delete Specific Keys
227
+
228
+ ```python
229
+ env.delete('OLD_KEY')
230
+ env.delete('TEMP_KEY', remove_from_os=True)
231
+ ```
232
+
233
+ ## Type Detection Rules
234
+
235
+ The package uses the following rules for automatic type detection:
236
+
237
+ - **Boolean**: `true`, `yes`, `on`, `1` → `True` | `false`, `no`, `off`, `0` → `False`
238
+ - **None**: `none`, `null`, empty string → `None`
239
+ - **Integer**: Numbers without decimal point → `int`
240
+ - **Float**: Numbers with decimal point → `float`
241
+ - **String**: Everything else → `str`
242
+
243
+ ## File Format Examples
244
+
245
+ ### .env
246
+ ```env
247
+ DEBUG=true
248
+ PORT=8080
249
+ DATABASE_URL=postgresql://localhost/mydb
250
+ ```
251
+
252
+ ### .json
253
+ ```json
254
+ {
255
+ "DEBUG": true,
256
+ "PORT": 8080,
257
+ "DATABASE_URL": "postgresql://localhost/mydb"
258
+ }
259
+ ```
260
+
261
+ ### .yaml
262
+ ```yaml
263
+ DEBUG: true
264
+ PORT: 8080
265
+ DATABASE_URL: postgresql://localhost/mydb
266
+ ```
267
+
268
+ ### .ini
269
+ ```ini
270
+ [DEFAULT]
271
+ DEBUG = true
272
+ PORT = 8080
273
+ DATABASE_URL = postgresql://localhost/mydb
274
+ ```
275
+
276
+ ## API Reference
277
+
278
+ ### DotEnv Class
279
+
280
+ #### `__init__(filepath=None, auto_load=True)`
281
+ Initialize DotEnv instance.
282
+
283
+ #### `load(filepath=None, override=True, apply_to_os=True)`
284
+ Load environment variables from file.
285
+
286
+ #### `get(key, default=None, cast_type=None)`
287
+ Get environment variable with automatic type detection.
288
+
289
+ #### `set(key, value, apply_to_os=True)`
290
+ Set environment variable.
291
+
292
+ #### `save(filepath=None, format=None)`
293
+ Save environment variables to file.
294
+
295
+ #### `delete(key, remove_from_os=True)`
296
+ Delete environment variable.
297
+
298
+ #### `all()`
299
+ Get all environment variables as dictionary.
300
+
301
+ #### `keys()`
302
+ Get all variable names.
303
+
304
+ #### `clear(clear_os=False)`
305
+ Clear all stored variables.
306
+
307
+ ### Convenience Functions
308
+
309
+ - `load_env(filepath=None, **kwargs)` - Load environment variables
310
+ - `get_env(key, default=None, cast_type=None)` - Get environment variable
311
+ - `set_env(key, value, **kwargs)` - Set environment variable
312
+ - `save_env(filepath=None, **kwargs)` - Save environment variables
313
+
314
+ ## License
315
+
316
+ MIT License
317
+
318
+ ## Contributing
319
+
320
+ Contributions are welcome! Please feel free to submit a Pull Request.
321
+
322
+
323
+ ## Author
324
+ [Hadi Cahyadi](mailto:cumulus13@gmail.com)
325
+
326
+
327
+ [![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/cumulus13)
328
+
329
+ [![Donate via Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/cumulus13)
330
+
331
+ [Support me on Patreon](https://www.patreon.com/cumulus13)
envdot-1.0.0/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # envdot
2
+
3
+ Enhanced environment variable management for Python with multi-format support and automatic type detection.
4
+
5
+ ## Features
6
+
7
+ - 🔧 **Multiple Format Support**: `.env`, `.json`, `.yaml`, `.yml`, and `.ini` files
8
+ - 🎯 **Automatic Type Detection**: Automatically converts strings to `bool`, `int`, `float`, or keeps as `string`
9
+ - 💾 **Read and Write**: Load from and save to configuration files
10
+ - 🔄 **Method Chaining**: Fluent API for cleaner code
11
+ - 🌍 **OS Environment Integration**: Seamlessly works with `os.environ`
12
+ - 📦 **Zero Dependencies**: Core functionality works without external packages (YAML support requires PyYAML)
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install envdot
18
+
19
+ # With YAML support
20
+ pip install envdot[yaml]
21
+
22
+ # With all extras
23
+ pip install envdot[all]
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ### Basic Usage
29
+
30
+ ```python
31
+ from envdot import DotEnv
32
+
33
+ # Auto-detect and load from common config files (.env, config.json, etc.)
34
+ env = DotEnv()
35
+
36
+ # Or specify a file
37
+ env = DotEnv('.env')
38
+
39
+ # Get values with automatic type detection
40
+ db_host = env.get('DB_HOST') # Returns string
41
+ db_port = env.get('DB_PORT') # Returns int (auto-detected)
42
+ debug_mode = env.get('DEBUG') # Returns bool (auto-detected)
43
+ api_timeout = env.get('API_TIMEOUT') # Returns float (auto-detected)
44
+
45
+ # Set values
46
+ env.set('NEW_KEY', 'value')
47
+ env.set('FEATURE_ENABLED', True)
48
+
49
+ # Save to file
50
+ env.save('.env')
51
+ ```
52
+
53
+ ### Convenience Functions
54
+
55
+ ```python
56
+ from envdot import load_env, get_env, set_env, save_env
57
+
58
+ # Load configuration
59
+ load_env('.env')
60
+
61
+ # Get values
62
+ database_url = get_env('DATABASE_URL')
63
+ max_connections = get_env('MAX_CONNECTIONS', default=100)
64
+
65
+ # Set values
66
+ set_env('NEW_FEATURE', True)
67
+
68
+ # Save changes
69
+ save_env('.env')
70
+ ```
71
+
72
+ ### Working with Different File Formats
73
+
74
+ #### .env File
75
+ ```python
76
+ env = DotEnv('.env')
77
+ env.load()
78
+ ```
79
+
80
+ #### JSON File
81
+ ```python
82
+ env = DotEnv('config.json')
83
+ env.load()
84
+ ```
85
+
86
+ #### YAML File
87
+ ```python
88
+ env = DotEnv('config.yaml')
89
+ env.load() # Requires PyYAML
90
+ ```
91
+
92
+ #### INI File
93
+ ```python
94
+ env = DotEnv('config.ini')
95
+ env.load()
96
+ ```
97
+
98
+ ### Type Detection Examples
99
+
100
+ The package automatically detects and converts types:
101
+
102
+ ```python
103
+ # Given this .env file:
104
+ # DEBUG=true
105
+ # PORT=8080
106
+ # TIMEOUT=30.5
107
+ # APP_NAME=MyApp
108
+ # EMPTY_VALUE=
109
+
110
+ env = DotEnv('.env')
111
+
112
+ env.get('DEBUG') # Returns: True (bool)
113
+ env.get('PORT') # Returns: 8080 (int)
114
+ env.get('TIMEOUT') # Returns: 30.5 (float)
115
+ env.get('APP_NAME') # Returns: 'MyApp' (str)
116
+ env.get('EMPTY_VALUE') # Returns: None
117
+ ```
118
+
119
+ ### Explicit Type Casting
120
+
121
+ ```python
122
+ # Force a specific type
123
+ version = env.get('VERSION', cast_type=str)
124
+ port = env.get('PORT', cast_type=int)
125
+ enabled = env.get('ENABLED', cast_type=bool)
126
+ ```
127
+
128
+ ### Method Chaining
129
+
130
+ ```python
131
+ env = DotEnv('.env') \
132
+ .load() \
133
+ .set('NEW_KEY', 'value') \
134
+ .set('ANOTHER_KEY', 123) \
135
+ .save()
136
+ ```
137
+
138
+ ### Dictionary-Style Access
139
+
140
+ ```python
141
+ env = DotEnv('.env')
142
+
143
+ # Get values
144
+ value = env['KEY_NAME']
145
+
146
+ # Set values
147
+ env['NEW_KEY'] = 'new value'
148
+
149
+ # Check existence
150
+ if 'API_KEY' in env:
151
+ print("API key is configured")
152
+
153
+ # Get all variables
154
+ all_vars = env.all()
155
+ ```
156
+
157
+ ### Advanced Features
158
+
159
+ #### Load Without Overriding
160
+
161
+ ```python
162
+ env.load(override=False) # Keep existing values
163
+ ```
164
+
165
+ #### Load Without Applying to OS Environment
166
+
167
+ ```python
168
+ env.load(apply_to_os=False) # Don't set in os.environ
169
+ ```
170
+
171
+ #### Save to Different Format
172
+
173
+ ```python
174
+ env = DotEnv('.env')
175
+ env.load()
176
+ env.save('config.json') # Convert .env to JSON
177
+ ```
178
+
179
+ #### Clear Variables
180
+
181
+ ```python
182
+ env.clear() # Clear internal storage only
183
+ env.clear(clear_os=True) # Also clear from os.environ
184
+ ```
185
+
186
+ #### Delete Specific Keys
187
+
188
+ ```python
189
+ env.delete('OLD_KEY')
190
+ env.delete('TEMP_KEY', remove_from_os=True)
191
+ ```
192
+
193
+ ## Type Detection Rules
194
+
195
+ The package uses the following rules for automatic type detection:
196
+
197
+ - **Boolean**: `true`, `yes`, `on`, `1` → `True` | `false`, `no`, `off`, `0` → `False`
198
+ - **None**: `none`, `null`, empty string → `None`
199
+ - **Integer**: Numbers without decimal point → `int`
200
+ - **Float**: Numbers with decimal point → `float`
201
+ - **String**: Everything else → `str`
202
+
203
+ ## File Format Examples
204
+
205
+ ### .env
206
+ ```env
207
+ DEBUG=true
208
+ PORT=8080
209
+ DATABASE_URL=postgresql://localhost/mydb
210
+ ```
211
+
212
+ ### .json
213
+ ```json
214
+ {
215
+ "DEBUG": true,
216
+ "PORT": 8080,
217
+ "DATABASE_URL": "postgresql://localhost/mydb"
218
+ }
219
+ ```
220
+
221
+ ### .yaml
222
+ ```yaml
223
+ DEBUG: true
224
+ PORT: 8080
225
+ DATABASE_URL: postgresql://localhost/mydb
226
+ ```
227
+
228
+ ### .ini
229
+ ```ini
230
+ [DEFAULT]
231
+ DEBUG = true
232
+ PORT = 8080
233
+ DATABASE_URL = postgresql://localhost/mydb
234
+ ```
235
+
236
+ ## API Reference
237
+
238
+ ### DotEnv Class
239
+
240
+ #### `__init__(filepath=None, auto_load=True)`
241
+ Initialize DotEnv instance.
242
+
243
+ #### `load(filepath=None, override=True, apply_to_os=True)`
244
+ Load environment variables from file.
245
+
246
+ #### `get(key, default=None, cast_type=None)`
247
+ Get environment variable with automatic type detection.
248
+
249
+ #### `set(key, value, apply_to_os=True)`
250
+ Set environment variable.
251
+
252
+ #### `save(filepath=None, format=None)`
253
+ Save environment variables to file.
254
+
255
+ #### `delete(key, remove_from_os=True)`
256
+ Delete environment variable.
257
+
258
+ #### `all()`
259
+ Get all environment variables as dictionary.
260
+
261
+ #### `keys()`
262
+ Get all variable names.
263
+
264
+ #### `clear(clear_os=False)`
265
+ Clear all stored variables.
266
+
267
+ ### Convenience Functions
268
+
269
+ - `load_env(filepath=None, **kwargs)` - Load environment variables
270
+ - `get_env(key, default=None, cast_type=None)` - Get environment variable
271
+ - `set_env(key, value, **kwargs)` - Set environment variable
272
+ - `save_env(filepath=None, **kwargs)` - Save environment variables
273
+
274
+ ## License
275
+
276
+ MIT License
277
+
278
+ ## Contributing
279
+
280
+ Contributions are welcome! Please feel free to submit a Pull Request.
281
+
282
+
283
+ ## Author
284
+ [Hadi Cahyadi](mailto:cumulus13@gmail.com)
285
+
286
+
287
+ [![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/cumulus13)
288
+
289
+ [![Donate via Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/cumulus13)
290
+
291
+ [Support me on Patreon](https://www.patreon.com/cumulus13)
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env python3
2
+ # file: envdot/__init__.py
3
+ # Author: Hadi Cahyadi <cumulus13@gmail.com>
4
+ # Date: 2025-10-10 23:59:34.906959
5
+ # License: MIT
6
+
7
+ """
8
+ envdot: Enhanced environment variable management with multi-format support
9
+ Supports .env, .json, .yaml, .yml, and .ini files with automatic type detection
10
+ """
11
+
12
+ from .core import DotEnv, load_env, get_env, set_env, save_env
13
+ from .exceptions import DotEnvError, FileNotFoundError, ParseError, TypeConversionError
14
+
15
+ __version__ = "1.0.0"
16
+ __all__ = [
17
+ "DotEnv",
18
+ "load_env",
19
+ "get_env",
20
+ "set_env",
21
+ "save_env",
22
+ "DotEnvError",
23
+ "FileNotFoundError",
24
+ "ParseError",
25
+ "TypeConversionError"
26
+ ]