secure-dotenv 0.1.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.
- secure_dotenv-0.1.0/LICENSE +21 -0
- secure_dotenv-0.1.0/PKG-INFO +294 -0
- secure_dotenv-0.1.0/README.md +275 -0
- secure_dotenv-0.1.0/pyproject.toml +32 -0
- secure_dotenv-0.1.0/secure_dotenv/__init__.py +25 -0
- secure_dotenv-0.1.0/secure_dotenv/cli.py +171 -0
- secure_dotenv-0.1.0/secure_dotenv/core.py +159 -0
- secure_dotenv-0.1.0/secure_dotenv/ui.py +300 -0
- secure_dotenv-0.1.0/secure_dotenv.egg-info/PKG-INFO +294 -0
- secure_dotenv-0.1.0/secure_dotenv.egg-info/SOURCES.txt +13 -0
- secure_dotenv-0.1.0/secure_dotenv.egg-info/dependency_links.txt +1 -0
- secure_dotenv-0.1.0/secure_dotenv.egg-info/entry_points.txt +2 -0
- secure_dotenv-0.1.0/secure_dotenv.egg-info/requires.txt +6 -0
- secure_dotenv-0.1.0/secure_dotenv.egg-info/top_level.txt +1 -0
- secure_dotenv-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nishanth
|
|
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,294 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: secure-dotenv
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The AI-safe, replacement for Python .env files.
|
|
5
|
+
Author-email: Nishanth K R <itsmenishanthkr@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: cryptography>=41.0.0
|
|
13
|
+
Requires-Dist: keyring>=24.0.0
|
|
14
|
+
Requires-Dist: watchdog>=3.0.0
|
|
15
|
+
Requires-Dist: fastapi>=0.100.0
|
|
16
|
+
Requires-Dist: uvicorn>=0.23.0
|
|
17
|
+
Requires-Dist: click>=8.1.0
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# 🔐 Secure dotenv
|
|
22
|
+
|
|
23
|
+
<img src="./assets/logo.png" alt="Secure dotenv" width="800"/>
|
|
24
|
+
|
|
25
|
+
**Secure dotenv** is a secure replacement for traditional `.env` files.
|
|
26
|
+
It automatically moves secrets into a secure vault while keeping your development workflow unchanged.
|
|
27
|
+
|
|
28
|
+
Your application still reads environment variables the same way — but **secrets never remain in plaintext `.env` files**.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
# Why Secure dotenv?
|
|
33
|
+
|
|
34
|
+
Traditional `.env` files are convenient but unsafe.
|
|
35
|
+
|
|
36
|
+
Common problems:
|
|
37
|
+
|
|
38
|
+
- Secrets stored in plaintext
|
|
39
|
+
- Secrets accidentally committed to Git
|
|
40
|
+
|
|
41
|
+
**Secure dotenv fixes this automatically.**
|
|
42
|
+
|
|
43
|
+
- Secrets are moved to a secure vault
|
|
44
|
+
- `.env` files keep only the keys
|
|
45
|
+
- Secrets are restored to memory at runtime
|
|
46
|
+
- No changes required in your application logic
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
# Features
|
|
51
|
+
|
|
52
|
+
- 🔐 Automatically moves secrets to a secure vault
|
|
53
|
+
- 🧠 Drop-in replacement for `dotenv`
|
|
54
|
+
- 🚫 Prevents accidental secret commits
|
|
55
|
+
- 🔁 Incremental secret migration
|
|
56
|
+
- 🗂 Supports multiple projects
|
|
57
|
+
- 🌎 Multiple environment profiles (`.env`, `.env.stage`, etc.)
|
|
58
|
+
- 🖥 Built-in local UI for managing secrets
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
# Quickstart
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install secure-dotenv
|
|
68
|
+
````
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Migrate an existing `.env` file
|
|
73
|
+
|
|
74
|
+
Run the following commands once to initialize and migrate your secrets.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# 1. initialize a vault
|
|
78
|
+
secure-dotenv init
|
|
79
|
+
|
|
80
|
+
# 2. migrate secrets to vault
|
|
81
|
+
secure-dotenv migrate
|
|
82
|
+
|
|
83
|
+
# this is a one-time activity
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
# Python Usage
|
|
89
|
+
|
|
90
|
+
Replace the standard dotenv import.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
#from dotenv import load_dotenv <- replace this
|
|
94
|
+
|
|
95
|
+
from secure_dotenv import load_dotenv
|
|
96
|
+
|
|
97
|
+
load_dotenv()
|
|
98
|
+
|
|
99
|
+
print(os.environ['OPENAI_API_KEY'])
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Your application code remains unchanged.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
# Web UI
|
|
107
|
+
|
|
108
|
+
Secure dotenv includes a simple UI for managing secrets.
|
|
109
|
+
|
|
110
|
+
Start the UI with:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
secure-dotenv ui
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
# How It Works
|
|
119
|
+
|
|
120
|
+
1. You create a normal `.env` file with keys and secret values.
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
OPENAI_API_KEY=sk-xxxx
|
|
124
|
+
DATABASE_PASSWORD=secret
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
2. When your program runs:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
load_dotenv()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Secure dotenv will:
|
|
134
|
+
|
|
135
|
+
* Move secret values into the vault
|
|
136
|
+
* Remove the values from the `.env` file
|
|
137
|
+
* Leave only the variable names behind
|
|
138
|
+
* Load the secrets into memory at runtime
|
|
139
|
+
|
|
140
|
+
Example result:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
OPENAI_API_KEY=
|
|
144
|
+
DATABASE_PASSWORD=
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Your secrets now live securely in the vault.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
# Basics
|
|
152
|
+
|
|
153
|
+
### Project Structure
|
|
154
|
+
|
|
155
|
+
Secrets are organized in a hierarchy:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
Project (unique id)
|
|
159
|
+
├── Profile (.env)
|
|
160
|
+
├── Profile (.env.stage)
|
|
161
|
+
└── Profile (.env.local)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Each profile contains its own secrets.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### Automatic Secret Protection
|
|
169
|
+
|
|
170
|
+
Every time `load_dotenv()` runs:
|
|
171
|
+
|
|
172
|
+
* Secret values are **removed from `.env`**
|
|
173
|
+
* Secrets are **loaded from vault into memory**
|
|
174
|
+
* Your application reads them normally using `os.environ`
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
### Incremental Secret Migration
|
|
179
|
+
|
|
180
|
+
You can keep editing your `.env` file normally.
|
|
181
|
+
|
|
182
|
+
Secure dotenv automatically detects changes.
|
|
183
|
+
|
|
184
|
+
* **Add a new secret** → automatically moved to vault
|
|
185
|
+
* **Update a secret value** → vault is updated
|
|
186
|
+
* **Existing secrets remain untouched**
|
|
187
|
+
|
|
188
|
+
No manual syncing required.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
# CLI Commands
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
Usage: secure-dotenv [OPTIONS] COMMAND [ARGS]...
|
|
196
|
+
|
|
197
|
+
secure_dotenv: The AI-safe replacement for .env files.
|
|
198
|
+
|
|
199
|
+
Options:
|
|
200
|
+
--help Show this message and exit.
|
|
201
|
+
|
|
202
|
+
Commands:
|
|
203
|
+
delete Delete a secret from a profile.
|
|
204
|
+
delete-profile Delete an entire environment profile (e.g., .env.local).
|
|
205
|
+
init Initializes the current folder as a secure_dotenv project.
|
|
206
|
+
migrate Syncs vault with local .env files.
|
|
207
|
+
projects List all secured projects in the vault.
|
|
208
|
+
restore Brings back the values from the vault into the env file.
|
|
209
|
+
secrets List secrets for the current project.
|
|
210
|
+
set Add or update a secret.
|
|
211
|
+
ui Starts the local web UI for managing secrets.
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
# Security Guarantee
|
|
217
|
+
|
|
218
|
+
With **Secure dotenv**, your project can never accidentally commit secrets to a repository.
|
|
219
|
+
|
|
220
|
+
Secrets are:
|
|
221
|
+
|
|
222
|
+
* stored in a vault
|
|
223
|
+
* removed from `.env` files
|
|
224
|
+
* loaded only in memory during runtime
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
# Example Workflow
|
|
229
|
+
|
|
230
|
+
1️⃣ Create `.env`
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
OPENAI_API_KEY=sk-xxxx
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
2️⃣ Create app.py
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
import os
|
|
240
|
+
from secure_dotenv import load_dotenv
|
|
241
|
+
load_dotenv()
|
|
242
|
+
|
|
243
|
+
print(os.environ['OPENAI_API_KEY'])
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
3️⃣ Run your program
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
python app.py
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
4️⃣ Secure dotenv automatically:
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
.env file becomes
|
|
257
|
+
|
|
258
|
+
OPENAI_API_KEY=
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
5️⃣ Secret safely stored in vault.
|
|
262
|
+
|
|
263
|
+
6️⃣ Restore to see the saved vaules
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
secure-dotenv restore
|
|
267
|
+
```
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
# When to Use Secure dotenv
|
|
271
|
+
|
|
272
|
+
* Local development
|
|
273
|
+
* AI / LLM projects
|
|
274
|
+
* DevOps pipelines
|
|
275
|
+
* Applications using API keys
|
|
276
|
+
* Teams worried about secret leaks
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
# Contributing
|
|
281
|
+
|
|
282
|
+
Contributions are welcome.
|
|
283
|
+
|
|
284
|
+
If you find bugs or have feature ideas, please open an issue or pull request.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
# License
|
|
289
|
+
|
|
290
|
+
MIT License
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
⭐ **If this project helps protect your secrets, consider giving it a star.**
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
|
|
2
|
+
# 🔐 Secure dotenv
|
|
3
|
+
|
|
4
|
+
<img src="./assets/logo.png" alt="Secure dotenv" width="800"/>
|
|
5
|
+
|
|
6
|
+
**Secure dotenv** is a secure replacement for traditional `.env` files.
|
|
7
|
+
It automatically moves secrets into a secure vault while keeping your development workflow unchanged.
|
|
8
|
+
|
|
9
|
+
Your application still reads environment variables the same way — but **secrets never remain in plaintext `.env` files**.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Why Secure dotenv?
|
|
14
|
+
|
|
15
|
+
Traditional `.env` files are convenient but unsafe.
|
|
16
|
+
|
|
17
|
+
Common problems:
|
|
18
|
+
|
|
19
|
+
- Secrets stored in plaintext
|
|
20
|
+
- Secrets accidentally committed to Git
|
|
21
|
+
|
|
22
|
+
**Secure dotenv fixes this automatically.**
|
|
23
|
+
|
|
24
|
+
- Secrets are moved to a secure vault
|
|
25
|
+
- `.env` files keep only the keys
|
|
26
|
+
- Secrets are restored to memory at runtime
|
|
27
|
+
- No changes required in your application logic
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
# Features
|
|
32
|
+
|
|
33
|
+
- 🔐 Automatically moves secrets to a secure vault
|
|
34
|
+
- 🧠 Drop-in replacement for `dotenv`
|
|
35
|
+
- 🚫 Prevents accidental secret commits
|
|
36
|
+
- 🔁 Incremental secret migration
|
|
37
|
+
- 🗂 Supports multiple projects
|
|
38
|
+
- 🌎 Multiple environment profiles (`.env`, `.env.stage`, etc.)
|
|
39
|
+
- 🖥 Built-in local UI for managing secrets
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
# Quickstart
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install secure-dotenv
|
|
49
|
+
````
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Migrate an existing `.env` file
|
|
54
|
+
|
|
55
|
+
Run the following commands once to initialize and migrate your secrets.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 1. initialize a vault
|
|
59
|
+
secure-dotenv init
|
|
60
|
+
|
|
61
|
+
# 2. migrate secrets to vault
|
|
62
|
+
secure-dotenv migrate
|
|
63
|
+
|
|
64
|
+
# this is a one-time activity
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
# Python Usage
|
|
70
|
+
|
|
71
|
+
Replace the standard dotenv import.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
#from dotenv import load_dotenv <- replace this
|
|
75
|
+
|
|
76
|
+
from secure_dotenv import load_dotenv
|
|
77
|
+
|
|
78
|
+
load_dotenv()
|
|
79
|
+
|
|
80
|
+
print(os.environ['OPENAI_API_KEY'])
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Your application code remains unchanged.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
# Web UI
|
|
88
|
+
|
|
89
|
+
Secure dotenv includes a simple UI for managing secrets.
|
|
90
|
+
|
|
91
|
+
Start the UI with:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
secure-dotenv ui
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
# How It Works
|
|
100
|
+
|
|
101
|
+
1. You create a normal `.env` file with keys and secret values.
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
OPENAI_API_KEY=sk-xxxx
|
|
105
|
+
DATABASE_PASSWORD=secret
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
2. When your program runs:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
load_dotenv()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Secure dotenv will:
|
|
115
|
+
|
|
116
|
+
* Move secret values into the vault
|
|
117
|
+
* Remove the values from the `.env` file
|
|
118
|
+
* Leave only the variable names behind
|
|
119
|
+
* Load the secrets into memory at runtime
|
|
120
|
+
|
|
121
|
+
Example result:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
OPENAI_API_KEY=
|
|
125
|
+
DATABASE_PASSWORD=
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Your secrets now live securely in the vault.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
# Basics
|
|
133
|
+
|
|
134
|
+
### Project Structure
|
|
135
|
+
|
|
136
|
+
Secrets are organized in a hierarchy:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
Project (unique id)
|
|
140
|
+
├── Profile (.env)
|
|
141
|
+
├── Profile (.env.stage)
|
|
142
|
+
└── Profile (.env.local)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Each profile contains its own secrets.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
### Automatic Secret Protection
|
|
150
|
+
|
|
151
|
+
Every time `load_dotenv()` runs:
|
|
152
|
+
|
|
153
|
+
* Secret values are **removed from `.env`**
|
|
154
|
+
* Secrets are **loaded from vault into memory**
|
|
155
|
+
* Your application reads them normally using `os.environ`
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### Incremental Secret Migration
|
|
160
|
+
|
|
161
|
+
You can keep editing your `.env` file normally.
|
|
162
|
+
|
|
163
|
+
Secure dotenv automatically detects changes.
|
|
164
|
+
|
|
165
|
+
* **Add a new secret** → automatically moved to vault
|
|
166
|
+
* **Update a secret value** → vault is updated
|
|
167
|
+
* **Existing secrets remain untouched**
|
|
168
|
+
|
|
169
|
+
No manual syncing required.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
# CLI Commands
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
Usage: secure-dotenv [OPTIONS] COMMAND [ARGS]...
|
|
177
|
+
|
|
178
|
+
secure_dotenv: The AI-safe replacement for .env files.
|
|
179
|
+
|
|
180
|
+
Options:
|
|
181
|
+
--help Show this message and exit.
|
|
182
|
+
|
|
183
|
+
Commands:
|
|
184
|
+
delete Delete a secret from a profile.
|
|
185
|
+
delete-profile Delete an entire environment profile (e.g., .env.local).
|
|
186
|
+
init Initializes the current folder as a secure_dotenv project.
|
|
187
|
+
migrate Syncs vault with local .env files.
|
|
188
|
+
projects List all secured projects in the vault.
|
|
189
|
+
restore Brings back the values from the vault into the env file.
|
|
190
|
+
secrets List secrets for the current project.
|
|
191
|
+
set Add or update a secret.
|
|
192
|
+
ui Starts the local web UI for managing secrets.
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
# Security Guarantee
|
|
198
|
+
|
|
199
|
+
With **Secure dotenv**, your project can never accidentally commit secrets to a repository.
|
|
200
|
+
|
|
201
|
+
Secrets are:
|
|
202
|
+
|
|
203
|
+
* stored in a vault
|
|
204
|
+
* removed from `.env` files
|
|
205
|
+
* loaded only in memory during runtime
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
# Example Workflow
|
|
210
|
+
|
|
211
|
+
1️⃣ Create `.env`
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
OPENAI_API_KEY=sk-xxxx
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
2️⃣ Create app.py
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
import os
|
|
221
|
+
from secure_dotenv import load_dotenv
|
|
222
|
+
load_dotenv()
|
|
223
|
+
|
|
224
|
+
print(os.environ['OPENAI_API_KEY'])
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
3️⃣ Run your program
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
python app.py
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
4️⃣ Secure dotenv automatically:
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
.env file becomes
|
|
238
|
+
|
|
239
|
+
OPENAI_API_KEY=
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
5️⃣ Secret safely stored in vault.
|
|
243
|
+
|
|
244
|
+
6️⃣ Restore to see the saved vaules
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
secure-dotenv restore
|
|
248
|
+
```
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
# When to Use Secure dotenv
|
|
252
|
+
|
|
253
|
+
* Local development
|
|
254
|
+
* AI / LLM projects
|
|
255
|
+
* DevOps pipelines
|
|
256
|
+
* Applications using API keys
|
|
257
|
+
* Teams worried about secret leaks
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
# Contributing
|
|
262
|
+
|
|
263
|
+
Contributions are welcome.
|
|
264
|
+
|
|
265
|
+
If you find bugs or have feature ideas, please open an issue or pull request.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
# License
|
|
270
|
+
|
|
271
|
+
MIT License
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
⭐ **If this project helps protect your secrets, consider giving it a star.**
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "secure-dotenv"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [{name = "Nishanth K R", email = "itsmenishanthkr@gmail.com"}]
|
|
9
|
+
description = "The AI-safe, replacement for Python .env files."
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.7"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
]
|
|
16
|
+
license="MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"cryptography>=41.0.0",
|
|
20
|
+
"keyring>=24.0.0",
|
|
21
|
+
"watchdog>=3.0.0",
|
|
22
|
+
"fastapi>=0.100.0",
|
|
23
|
+
"uvicorn>=0.23.0",
|
|
24
|
+
"click>=8.1.0"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
secure-dotenv = "secure_dotenv.cli:cli"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
include = ["secure_dotenv*"] # Only include your code
|
|
32
|
+
exclude = ["assets*", "tests*"] # Explicitly ignore the assets folder
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import warnings
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from .core import get_project_secrets, parse_env_file
|
|
5
|
+
|
|
6
|
+
def load_dotenv(dotenv_path=".env", override=False, **kwargs):
|
|
7
|
+
project_root = Path.cwd()
|
|
8
|
+
env_path = project_root / dotenv_path
|
|
9
|
+
id_file = project_root / ".secure-env-id"
|
|
10
|
+
|
|
11
|
+
if not id_file.exists():
|
|
12
|
+
return # Standard behavior if not initialized
|
|
13
|
+
|
|
14
|
+
project_id = id_file.read_text().strip()
|
|
15
|
+
|
|
16
|
+
# 1. Perform Migration/Sync automatically
|
|
17
|
+
if env_path.exists():
|
|
18
|
+
from .core import migrate_and_clear_env
|
|
19
|
+
migrate_and_clear_env(str(env_path), project_id)
|
|
20
|
+
|
|
21
|
+
# 2. Load into memory from Vault
|
|
22
|
+
secrets = get_project_secrets(project_id, Path(dotenv_path).name)
|
|
23
|
+
for key, value in secrets.items():
|
|
24
|
+
if override or key not in os.environ:
|
|
25
|
+
os.environ[key] = value
|