fastenv 0.4.2__tar.gz → 0.6.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.
- {fastenv-0.4.2 → fastenv-0.6.0}/PKG-INFO +46 -6
- {fastenv-0.4.2 → fastenv-0.6.0}/README.md +39 -0
- {fastenv-0.4.2 → fastenv-0.6.0}/fastenv/__init__.py +1 -1
- {fastenv-0.4.2 → fastenv-0.6.0}/fastenv/dotenv.py +4 -3
- {fastenv-0.4.2 → fastenv-0.6.0}/fastenv/types.py +2 -2
- {fastenv-0.4.2 → fastenv-0.6.0}/pyproject.toml +9 -8
- {fastenv-0.4.2 → fastenv-0.6.0}/.gitignore +0 -0
- {fastenv-0.4.2 → fastenv-0.6.0}/LICENSE +0 -0
- {fastenv-0.4.2 → fastenv-0.6.0}/fastenv/cloud/__init__.py +0 -0
- {fastenv-0.4.2 → fastenv-0.6.0}/fastenv/cloud/object_storage.py +0 -0
- {fastenv-0.4.2 → fastenv-0.6.0}/fastenv/py.typed +0 -0
- {fastenv-0.4.2 → fastenv-0.6.0}/fastenv/utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fastenv
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Unified environment variable and settings management for FastAPI and beyond.
|
|
5
5
|
Project-URL: Documentation, https://fastenv.bws.bio
|
|
6
6
|
Project-URL: Homepage, https://github.com/br3ndonland/fastenv
|
|
@@ -13,21 +13,21 @@ Classifier: Environment :: Web Environment
|
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: Natural Language :: English
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
20
|
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
22
22
|
Classifier: Topic :: System :: Installation/Setup
|
|
23
23
|
Classifier: Topic :: System :: Systems Administration
|
|
24
24
|
Classifier: Topic :: Utilities
|
|
25
25
|
Classifier: Typing :: Typed
|
|
26
|
-
Requires-Python: <4,>=3.
|
|
26
|
+
Requires-Python: <4,>=3.9
|
|
27
27
|
Requires-Dist: anyio<5,>=3.3
|
|
28
28
|
Provides-Extra: checks
|
|
29
|
-
Requires-Dist: mypy==1.
|
|
30
|
-
Requires-Dist: ruff<0.
|
|
29
|
+
Requires-Dist: mypy==1.11.2; extra == 'checks'
|
|
30
|
+
Requires-Dist: ruff<0.7,>=0.6; extra == 'checks'
|
|
31
31
|
Provides-Extra: cloud
|
|
32
32
|
Requires-Dist: httpx<1,>=0.23; extra == 'cloud'
|
|
33
33
|
Provides-Extra: docs
|
|
@@ -36,10 +36,11 @@ Provides-Extra: httpx
|
|
|
36
36
|
Requires-Dist: httpx<1,>=0.23; extra == 'httpx'
|
|
37
37
|
Provides-Extra: tests
|
|
38
38
|
Requires-Dist: coverage[toml]<8,>=7; extra == 'tests'
|
|
39
|
+
Requires-Dist: fastapi<0.116,>=0.110.1; extra == 'tests'
|
|
39
40
|
Requires-Dist: freezegun<2,>=1; extra == 'tests'
|
|
40
41
|
Requires-Dist: httpx<1,>=0.23; extra == 'tests'
|
|
41
42
|
Requires-Dist: pytest-mock<4,>=3; extra == 'tests'
|
|
42
|
-
Requires-Dist: pytest<8
|
|
43
|
+
Requires-Dist: pytest<9,>=8.1.1; extra == 'tests'
|
|
43
44
|
Description-Content-Type: text/markdown
|
|
44
45
|
|
|
45
46
|
# ⚙️ fastenv 🚀
|
|
@@ -53,6 +54,8 @@ _Unified environment variable and settings management for FastAPI and beyond_
|
|
|
53
54
|
|
|
54
55
|
## Description
|
|
55
56
|
|
|
57
|
+
fastenv [\[fæst iː ən v\]](https://en.wikipedia.org/wiki/Help:IPA/English) is a Python package for managing environment variables and application settings.
|
|
58
|
+
|
|
56
59
|
[Environment variables](https://en.wikipedia.org/wiki/Environment_variable) are key-value pairs provided to the operating system with syntax like `VARIABLE_NAME=value`. Collections of environment variables are stored in files commonly named _.env_ and called "dotenv" files. The Python standard library `os` module provides tools for reading environment variables, such as `os.getenv("VARIABLE_NAME")`, but only handles strings, and doesn't include tools for file I/O. Additional logic is therefore needed to load environment variables from files before they can be read by Python, and to convert variables from strings to other Python types.
|
|
57
60
|
|
|
58
61
|
This project aims to:
|
|
@@ -65,6 +68,8 @@ This project aims to:
|
|
|
65
68
|
|
|
66
69
|
The source code is 100% type-annotated and unit-tested.
|
|
67
70
|
|
|
71
|
+
For additional background on the project, see [www.bws.bio/projects/fastenv](https://www.bws.bio/projects/fastenv).
|
|
72
|
+
|
|
68
73
|
## Quickstart
|
|
69
74
|
|
|
70
75
|
Install fastenv into a virtual environment:
|
|
@@ -101,6 +106,41 @@ anyio.run(fastenv.dump_dotenv, dotenv)
|
|
|
101
106
|
# Path('/path/to/this/dir/.env')
|
|
102
107
|
```
|
|
103
108
|
|
|
109
|
+
Use fastenv in your FastAPI app:
|
|
110
|
+
|
|
111
|
+
```py
|
|
112
|
+
from contextlib import asynccontextmanager
|
|
113
|
+
from typing import AsyncIterator, TypedDict
|
|
114
|
+
|
|
115
|
+
import fastenv
|
|
116
|
+
from fastapi import FastAPI, Request
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class LifespanState(TypedDict):
|
|
120
|
+
settings: fastenv.DotEnv
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@asynccontextmanager
|
|
124
|
+
async def lifespan(_: FastAPI) -> AsyncIterator[LifespanState]:
|
|
125
|
+
"""Configure app lifespan.
|
|
126
|
+
|
|
127
|
+
https://fastapi.tiangolo.com/advanced/events/
|
|
128
|
+
https://www.starlette.io/lifespan/
|
|
129
|
+
"""
|
|
130
|
+
settings = await fastenv.load_dotenv(".env")
|
|
131
|
+
lifespan_state: LifespanState = {"settings": settings}
|
|
132
|
+
yield lifespan_state
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
app = FastAPI(lifespan=lifespan)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@app.get("/settings")
|
|
139
|
+
async def get_settings(request: Request) -> dict[str, str]:
|
|
140
|
+
settings = request.state.settings
|
|
141
|
+
return dict(settings)
|
|
142
|
+
```
|
|
143
|
+
|
|
104
144
|
## Documentation
|
|
105
145
|
|
|
106
146
|
Documentation is built with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/), deployed on [Vercel](https://vercel.com/), and available at [fastenv.bws.bio](https://fastenv.bws.bio) and [fastenv.vercel.app](https://fastenv.vercel.app).
|
|
@@ -9,6 +9,8 @@ _Unified environment variable and settings management for FastAPI and beyond_
|
|
|
9
9
|
|
|
10
10
|
## Description
|
|
11
11
|
|
|
12
|
+
fastenv [\[fæst iː ən v\]](https://en.wikipedia.org/wiki/Help:IPA/English) is a Python package for managing environment variables and application settings.
|
|
13
|
+
|
|
12
14
|
[Environment variables](https://en.wikipedia.org/wiki/Environment_variable) are key-value pairs provided to the operating system with syntax like `VARIABLE_NAME=value`. Collections of environment variables are stored in files commonly named _.env_ and called "dotenv" files. The Python standard library `os` module provides tools for reading environment variables, such as `os.getenv("VARIABLE_NAME")`, but only handles strings, and doesn't include tools for file I/O. Additional logic is therefore needed to load environment variables from files before they can be read by Python, and to convert variables from strings to other Python types.
|
|
13
15
|
|
|
14
16
|
This project aims to:
|
|
@@ -21,6 +23,8 @@ This project aims to:
|
|
|
21
23
|
|
|
22
24
|
The source code is 100% type-annotated and unit-tested.
|
|
23
25
|
|
|
26
|
+
For additional background on the project, see [www.bws.bio/projects/fastenv](https://www.bws.bio/projects/fastenv).
|
|
27
|
+
|
|
24
28
|
## Quickstart
|
|
25
29
|
|
|
26
30
|
Install fastenv into a virtual environment:
|
|
@@ -57,6 +61,41 @@ anyio.run(fastenv.dump_dotenv, dotenv)
|
|
|
57
61
|
# Path('/path/to/this/dir/.env')
|
|
58
62
|
```
|
|
59
63
|
|
|
64
|
+
Use fastenv in your FastAPI app:
|
|
65
|
+
|
|
66
|
+
```py
|
|
67
|
+
from contextlib import asynccontextmanager
|
|
68
|
+
from typing import AsyncIterator, TypedDict
|
|
69
|
+
|
|
70
|
+
import fastenv
|
|
71
|
+
from fastapi import FastAPI, Request
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class LifespanState(TypedDict):
|
|
75
|
+
settings: fastenv.DotEnv
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@asynccontextmanager
|
|
79
|
+
async def lifespan(_: FastAPI) -> AsyncIterator[LifespanState]:
|
|
80
|
+
"""Configure app lifespan.
|
|
81
|
+
|
|
82
|
+
https://fastapi.tiangolo.com/advanced/events/
|
|
83
|
+
https://www.starlette.io/lifespan/
|
|
84
|
+
"""
|
|
85
|
+
settings = await fastenv.load_dotenv(".env")
|
|
86
|
+
lifespan_state: LifespanState = {"settings": settings}
|
|
87
|
+
yield lifespan_state
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
app = FastAPI(lifespan=lifespan)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@app.get("/settings")
|
|
94
|
+
async def get_settings(request: Request) -> dict[str, str]:
|
|
95
|
+
settings = request.state.settings
|
|
96
|
+
return dict(settings)
|
|
97
|
+
```
|
|
98
|
+
|
|
60
99
|
## Documentation
|
|
61
100
|
|
|
62
101
|
Documentation is built with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/), deployed on [Vercel](https://vercel.com/), and available at [fastenv.bws.bio](https://fastenv.bws.bio) and [fastenv.vercel.app](https://fastenv.vercel.app).
|
|
@@ -2,14 +2,15 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
import shlex
|
|
5
|
-
from
|
|
5
|
+
from collections.abc import MutableMapping
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
6
7
|
|
|
7
8
|
import anyio
|
|
8
9
|
|
|
9
10
|
from fastenv.utilities import logger
|
|
10
11
|
|
|
11
12
|
if TYPE_CHECKING:
|
|
12
|
-
from
|
|
13
|
+
from collections.abc import Iterator
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class DotEnv(MutableMapping[str, str]):
|
|
@@ -82,7 +83,7 @@ class DotEnv(MutableMapping[str, str]):
|
|
|
82
83
|
return tuple(
|
|
83
84
|
(split_arg[0].strip(" \n\"'").upper(), split_arg[1].strip(" \n\"'"))
|
|
84
85
|
for a in parsed_args
|
|
85
|
-
if len(
|
|
86
|
+
if len(split_arg := a.split(sep="=", maxsplit=1)) == 2
|
|
86
87
|
)
|
|
87
88
|
|
|
88
89
|
def _parse_kwargs(self, **kwargs: str) -> dict[str, str]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING,
|
|
3
|
+
from typing import TYPE_CHECKING, TypedDict, Union
|
|
4
4
|
|
|
5
5
|
if TYPE_CHECKING:
|
|
6
6
|
import sys
|
|
@@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
|
|
10
10
|
else:
|
|
11
11
|
from typing import TypeAlias
|
|
12
12
|
|
|
13
|
-
UploadPolicyConditions: TypeAlias =
|
|
13
|
+
UploadPolicyConditions: TypeAlias = list[Union[dict[str, str], list[Union[str, int]]]]
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class UploadPolicy(TypedDict):
|
|
@@ -9,10 +9,10 @@ classifiers = [
|
|
|
9
9
|
"Intended Audience :: Developers",
|
|
10
10
|
"Natural Language :: English",
|
|
11
11
|
"Programming Language :: Python :: 3",
|
|
12
|
-
"Programming Language :: Python :: 3.8",
|
|
13
12
|
"Programming Language :: Python :: 3.9",
|
|
14
13
|
"Programming Language :: Python :: 3.10",
|
|
15
14
|
"Programming Language :: Python :: 3.11",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
16
|
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
|
|
17
17
|
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
18
18
|
"Topic :: System :: Installation/Setup",
|
|
@@ -29,12 +29,12 @@ keywords = ["asgi", "dotenv", "environment variables", "fastapi", "settings"]
|
|
|
29
29
|
license = "MIT"
|
|
30
30
|
name = "fastenv"
|
|
31
31
|
readme = "README.md"
|
|
32
|
-
requires-python = ">=3.
|
|
32
|
+
requires-python = ">=3.9,<4"
|
|
33
33
|
|
|
34
34
|
[project.optional-dependencies]
|
|
35
35
|
checks = [
|
|
36
|
-
"mypy==1.
|
|
37
|
-
"ruff>=0.
|
|
36
|
+
"mypy==1.11.2",
|
|
37
|
+
"ruff>=0.6,<0.7",
|
|
38
38
|
]
|
|
39
39
|
cloud = [
|
|
40
40
|
"httpx>=0.23,<1",
|
|
@@ -47,9 +47,10 @@ httpx = [
|
|
|
47
47
|
]
|
|
48
48
|
tests = [
|
|
49
49
|
"coverage[toml]>=7,<8",
|
|
50
|
+
"fastapi>=0.110.1,<0.116",
|
|
50
51
|
"freezegun>=1,<2",
|
|
51
52
|
"httpx>=0.23,<1",
|
|
52
|
-
"pytest>=
|
|
53
|
+
"pytest>=8.1.1,<9",
|
|
53
54
|
"pytest-mock>=3,<4",
|
|
54
55
|
]
|
|
55
56
|
|
|
@@ -86,13 +87,13 @@ check = [
|
|
|
86
87
|
"ruff check",
|
|
87
88
|
"ruff format --check",
|
|
88
89
|
"mypy",
|
|
89
|
-
"npx -s -y prettier@'^
|
|
90
|
+
"npx -s -y prettier@'^3' . --check",
|
|
90
91
|
"npx -s -y cspell --dot --gitignore *.md **/*.md",
|
|
91
92
|
]
|
|
92
93
|
format = [
|
|
93
94
|
"ruff check --fix",
|
|
94
95
|
"ruff format",
|
|
95
|
-
"npx -s -y prettier@'^
|
|
96
|
+
"npx -s -y prettier@'^3' . --write",
|
|
96
97
|
]
|
|
97
98
|
|
|
98
99
|
[tool.hatch.envs.docs]
|
|
@@ -130,7 +131,7 @@ src = ["fastenv", "tests"]
|
|
|
130
131
|
docstring-code-format = true
|
|
131
132
|
|
|
132
133
|
[tool.ruff.lint]
|
|
133
|
-
extend-select = ["I"]
|
|
134
|
+
extend-select = ["I", "UP"]
|
|
134
135
|
|
|
135
136
|
[tool.ruff.lint.isort]
|
|
136
137
|
known-first-party = ["fastenv", "tests"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|