nacho-python 1.0.0__tar.gz → 1.1.1__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.
- nacho_python-1.1.1/PKG-INFO +174 -0
- nacho_python-1.1.1/README.md +124 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/_version.py +1 -1
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/cli/main.py +9 -8
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/client.py +41 -41
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/config.py +112 -120
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/env.py +5 -5
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/event.py +31 -33
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/schema.py +9 -9
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/server/__init__.py +1 -1
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/server/app.py +29 -29
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/server/auth.py +8 -7
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/server/models.py +14 -14
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/server/runtime.py +57 -52
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/server/ui/index.html +1 -1
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/storage/__init__.py +1 -1
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/storage/base.py +8 -7
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/storage/file.py +4 -4
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/storage/remote.py +17 -17
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/utils/io.py +7 -19
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/utils/path.py +8 -7
- nacho_python-1.1.1/nacho_python.egg-info/PKG-INFO +174 -0
- nacho_python-1.1.1/nacho_python.egg-info/requires.txt +38 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/pyproject.toml +32 -23
- nacho_python-1.0.0/PKG-INFO +0 -875
- nacho_python-1.0.0/README.md +0 -827
- nacho_python-1.0.0/nacho_python.egg-info/PKG-INFO +0 -875
- nacho_python-1.0.0/nacho_python.egg-info/requires.txt +0 -36
- {nacho_python-1.0.0 → nacho_python-1.1.1}/LICENSE +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/MANIFEST.in +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/__init__.py +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/cli/__init__.py +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho/utils/__init__.py +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho_python.egg-info/SOURCES.txt +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho_python.egg-info/dependency_links.txt +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho_python.egg-info/entry_points.txt +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/nacho_python.egg-info/top_level.txt +0 -0
- {nacho_python-1.0.0 → nacho_python-1.1.1}/setup.cfg +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nacho-python
|
|
3
|
+
Version: 1.1.1
|
|
4
|
+
Summary: Nacho - Lightweight, schema-first dynamic configuration service
|
|
5
|
+
Author-email: "Nya Foundation Team (k3scat)" <k3scat@github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/nya-foundation/nacho
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/nya-foundation/nacho/issues
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
19
|
+
Requires-Dist: tomli-w>=1.1.0
|
|
20
|
+
Provides-Extra: server
|
|
21
|
+
Requires-Dist: fastapi>=0.115.0; extra == "server"
|
|
22
|
+
Requires-Dist: pydantic>=2.9.0; extra == "server"
|
|
23
|
+
Requires-Dist: uvicorn>=0.32.0; extra == "server"
|
|
24
|
+
Requires-Dist: websockets>=13.0; extra == "server"
|
|
25
|
+
Provides-Extra: remote
|
|
26
|
+
Requires-Dist: requests>=2.32.0; extra == "remote"
|
|
27
|
+
Requires-Dist: websocket-client>=1.8.0; extra == "remote"
|
|
28
|
+
Provides-Extra: schema
|
|
29
|
+
Requires-Dist: jsonschema>=4.23.0; extra == "schema"
|
|
30
|
+
Requires-Dist: rfc3986-validator>=0.1.1; extra == "schema"
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: nacho-python[remote,schema,server]; extra == "all"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=8.3.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=6.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
|
|
37
|
+
Requires-Dist: httpx>=0.27.0; extra == "dev"
|
|
38
|
+
Requires-Dist: httpx2>=2.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: nacho-python[all]; extra == "dev"
|
|
40
|
+
Provides-Extra: lint
|
|
41
|
+
Requires-Dist: ruff>=0.15.0; extra == "lint"
|
|
42
|
+
Requires-Dist: mypy>=1.14.0; extra == "lint"
|
|
43
|
+
Requires-Dist: types-pyyaml; extra == "lint"
|
|
44
|
+
Requires-Dist: types-requests; extra == "lint"
|
|
45
|
+
Requires-Dist: types-jsonschema; extra == "lint"
|
|
46
|
+
Provides-Extra: uitest
|
|
47
|
+
Requires-Dist: playwright>=1.45; extra == "uitest"
|
|
48
|
+
Requires-Dist: pytest-playwright>=0.5.0; extra == "uitest"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
<div align="center">
|
|
52
|
+
|
|
53
|
+
<picture>
|
|
54
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-dark.svg">
|
|
55
|
+
<img src="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-light.svg" alt="Nacho" width="300">
|
|
56
|
+
</picture>
|
|
57
|
+
|
|
58
|
+
**Dynamic configuration for Python.**<br>
|
|
59
|
+
A library for local files, and a server when changes need to reach running services.
|
|
60
|
+
|
|
61
|
+
[English](https://github.com/Nya-Foundation/nacho/blob/main/README.md) ·
|
|
62
|
+
[中文](https://github.com/Nya-Foundation/nacho/blob/main/README_zh.md) ·
|
|
63
|
+
[日本語](https://github.com/Nya-Foundation/nacho/blob/main/README_ja.md)
|
|
64
|
+
|
|
65
|
+
[](https://pypi.org/project/nacho-python/)
|
|
66
|
+
[](https://pypi.org/project/nacho-python/)
|
|
67
|
+
[](https://codecov.io/gh/nya-foundation/nacho)
|
|
68
|
+
[](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
69
|
+
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
Nacho treats configuration as validated, versioned data. Use it as a library
|
|
73
|
+
against a local file, or run its server so that every connected service
|
|
74
|
+
receives a change the moment it is made, with no redeploy and no restart.
|
|
75
|
+
|
|
76
|
+
- **Validated.** Every write is checked against a JSON Schema, and optionally
|
|
77
|
+
your own rules, before it is stored.
|
|
78
|
+
- **Live.** Services subscribe over WebSocket and react through event handlers.
|
|
79
|
+
- **Versioned.** Every revision is kept and can be inspected, compared, and
|
|
80
|
+
restored.
|
|
81
|
+
- **Safe under concurrency.** Revision-checked writes turn lost updates into
|
|
82
|
+
explicit conflicts.
|
|
83
|
+
- **Format-agnostic.** JSON, YAML, and TOML are interchangeable in files, API
|
|
84
|
+
payloads, and the editor.
|
|
85
|
+
- **Self-contained.** The server ships a REST API, a CLI, and a single-file
|
|
86
|
+
web UI with no build step.
|
|
87
|
+
|
|
88
|
+
## Install
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install nacho-python # library: local files and in-memory configs
|
|
92
|
+
pip install "nacho-python[schema]" # + JSON Schema validation
|
|
93
|
+
pip install "nacho-python[server]" # + configuration server and web UI
|
|
94
|
+
pip install "nacho-python[remote]" # + client for a configuration server
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Requires Python 3.11 or later. A container image is published as
|
|
98
|
+
`k3scat/nacho` and `ghcr.io/nya-foundation/nacho`.
|
|
99
|
+
|
|
100
|
+
## Use it as a library
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from nacho import Nacho
|
|
104
|
+
|
|
105
|
+
config = Nacho("config.yaml", schema="schema.json", events=True)
|
|
106
|
+
|
|
107
|
+
port = config.get_int("server.port", default=8000)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@config.on_change("features.*")
|
|
111
|
+
def on_flag_change(path, new_value, **_):
|
|
112
|
+
print(f"{path} is now {new_value}")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
config.set("features.beta", True) # validated, then on_flag_change fires
|
|
116
|
+
config.save()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Run a server
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
nacho server --config config.yaml --schema schema.json --api-key "$NACHO_KEY"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The server listens on `http://127.0.0.1:8000` and serves the REST API, the
|
|
126
|
+
web UI at `/ui`, and interactive API documentation at `/docs`.
|
|
127
|
+
|
|
128
|
+
## Connect a service
|
|
129
|
+
|
|
130
|
+
Swap the file for a `RemoteStorageBackend`. The rest of the code stays the
|
|
131
|
+
same, and handlers now fire when anyone changes the configuration on the
|
|
132
|
+
server.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from nacho import Nacho, RemoteStorageBackend
|
|
136
|
+
|
|
137
|
+
config = Nacho(
|
|
138
|
+
storage=RemoteStorageBackend(
|
|
139
|
+
url="http://127.0.0.1:8000",
|
|
140
|
+
app_name="my-service",
|
|
141
|
+
api_key="...",
|
|
142
|
+
watch=True,
|
|
143
|
+
),
|
|
144
|
+
events=True,
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Documentation
|
|
149
|
+
|
|
150
|
+
| Guide | Covers |
|
|
151
|
+
|---|---|
|
|
152
|
+
| [Library](https://github.com/Nya-Foundation/nacho/blob/main/docs/library.md) | Reading and writing, transactions, validation, events, environment overrides |
|
|
153
|
+
| [Remote client](https://github.com/Nya-Foundation/nacho/blob/main/docs/remote-client.md) | Connecting a service to a server, conflicts, reconnection |
|
|
154
|
+
| [Server](https://github.com/Nya-Foundation/nacho/blob/main/docs/server.md) | Running and embedding the server, the web UI, authentication, Docker |
|
|
155
|
+
| [REST API](https://github.com/Nya-Foundation/nacho/blob/main/docs/rest-api.md) | Endpoints, payloads, revisions, history, the WebSocket stream |
|
|
156
|
+
| [CLI](https://github.com/Nya-Foundation/nacho/blob/main/docs/cli.md) | Every `nacho` command and its exit codes |
|
|
157
|
+
|
|
158
|
+
## Project status
|
|
159
|
+
|
|
160
|
+
Nacho is feature-complete and in maintenance mode. It receives bug fixes,
|
|
161
|
+
security fixes, and dependency updates; new features are not planned. The
|
|
162
|
+
public API (the `Nacho` class, the storage backends, the REST API, and the
|
|
163
|
+
CLI) is stable under semantic versioning.
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
See [CONTRIBUTING.md](https://github.com/Nya-Foundation/nacho/blob/main/CONTRIBUTING.md).
|
|
168
|
+
Questions and bug reports go to the
|
|
169
|
+
[issue tracker](https://github.com/Nya-Foundation/nacho/issues) or the
|
|
170
|
+
[Nya Foundation Discord](https://discord.gg/jXAxVPSs7K).
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
[MIT](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-dark.svg">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-light.svg" alt="Nacho" width="300">
|
|
6
|
+
</picture>
|
|
7
|
+
|
|
8
|
+
**Dynamic configuration for Python.**<br>
|
|
9
|
+
A library for local files, and a server when changes need to reach running services.
|
|
10
|
+
|
|
11
|
+
[English](https://github.com/Nya-Foundation/nacho/blob/main/README.md) ·
|
|
12
|
+
[中文](https://github.com/Nya-Foundation/nacho/blob/main/README_zh.md) ·
|
|
13
|
+
[日本語](https://github.com/Nya-Foundation/nacho/blob/main/README_ja.md)
|
|
14
|
+
|
|
15
|
+
[](https://pypi.org/project/nacho-python/)
|
|
16
|
+
[](https://pypi.org/project/nacho-python/)
|
|
17
|
+
[](https://codecov.io/gh/nya-foundation/nacho)
|
|
18
|
+
[](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
Nacho treats configuration as validated, versioned data. Use it as a library
|
|
23
|
+
against a local file, or run its server so that every connected service
|
|
24
|
+
receives a change the moment it is made, with no redeploy and no restart.
|
|
25
|
+
|
|
26
|
+
- **Validated.** Every write is checked against a JSON Schema, and optionally
|
|
27
|
+
your own rules, before it is stored.
|
|
28
|
+
- **Live.** Services subscribe over WebSocket and react through event handlers.
|
|
29
|
+
- **Versioned.** Every revision is kept and can be inspected, compared, and
|
|
30
|
+
restored.
|
|
31
|
+
- **Safe under concurrency.** Revision-checked writes turn lost updates into
|
|
32
|
+
explicit conflicts.
|
|
33
|
+
- **Format-agnostic.** JSON, YAML, and TOML are interchangeable in files, API
|
|
34
|
+
payloads, and the editor.
|
|
35
|
+
- **Self-contained.** The server ships a REST API, a CLI, and a single-file
|
|
36
|
+
web UI with no build step.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install nacho-python # library: local files and in-memory configs
|
|
42
|
+
pip install "nacho-python[schema]" # + JSON Schema validation
|
|
43
|
+
pip install "nacho-python[server]" # + configuration server and web UI
|
|
44
|
+
pip install "nacho-python[remote]" # + client for a configuration server
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires Python 3.11 or later. A container image is published as
|
|
48
|
+
`k3scat/nacho` and `ghcr.io/nya-foundation/nacho`.
|
|
49
|
+
|
|
50
|
+
## Use it as a library
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from nacho import Nacho
|
|
54
|
+
|
|
55
|
+
config = Nacho("config.yaml", schema="schema.json", events=True)
|
|
56
|
+
|
|
57
|
+
port = config.get_int("server.port", default=8000)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@config.on_change("features.*")
|
|
61
|
+
def on_flag_change(path, new_value, **_):
|
|
62
|
+
print(f"{path} is now {new_value}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
config.set("features.beta", True) # validated, then on_flag_change fires
|
|
66
|
+
config.save()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Run a server
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
nacho server --config config.yaml --schema schema.json --api-key "$NACHO_KEY"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The server listens on `http://127.0.0.1:8000` and serves the REST API, the
|
|
76
|
+
web UI at `/ui`, and interactive API documentation at `/docs`.
|
|
77
|
+
|
|
78
|
+
## Connect a service
|
|
79
|
+
|
|
80
|
+
Swap the file for a `RemoteStorageBackend`. The rest of the code stays the
|
|
81
|
+
same, and handlers now fire when anyone changes the configuration on the
|
|
82
|
+
server.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from nacho import Nacho, RemoteStorageBackend
|
|
86
|
+
|
|
87
|
+
config = Nacho(
|
|
88
|
+
storage=RemoteStorageBackend(
|
|
89
|
+
url="http://127.0.0.1:8000",
|
|
90
|
+
app_name="my-service",
|
|
91
|
+
api_key="...",
|
|
92
|
+
watch=True,
|
|
93
|
+
),
|
|
94
|
+
events=True,
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Documentation
|
|
99
|
+
|
|
100
|
+
| Guide | Covers |
|
|
101
|
+
|---|---|
|
|
102
|
+
| [Library](https://github.com/Nya-Foundation/nacho/blob/main/docs/library.md) | Reading and writing, transactions, validation, events, environment overrides |
|
|
103
|
+
| [Remote client](https://github.com/Nya-Foundation/nacho/blob/main/docs/remote-client.md) | Connecting a service to a server, conflicts, reconnection |
|
|
104
|
+
| [Server](https://github.com/Nya-Foundation/nacho/blob/main/docs/server.md) | Running and embedding the server, the web UI, authentication, Docker |
|
|
105
|
+
| [REST API](https://github.com/Nya-Foundation/nacho/blob/main/docs/rest-api.md) | Endpoints, payloads, revisions, history, the WebSocket stream |
|
|
106
|
+
| [CLI](https://github.com/Nya-Foundation/nacho/blob/main/docs/cli.md) | Every `nacho` command and its exit codes |
|
|
107
|
+
|
|
108
|
+
## Project status
|
|
109
|
+
|
|
110
|
+
Nacho is feature-complete and in maintenance mode. It receives bug fixes,
|
|
111
|
+
security fixes, and dependency updates; new features are not planned. The
|
|
112
|
+
public API (the `Nacho` class, the storage backends, the REST API, and the
|
|
113
|
+
CLI) is stable under semantic versioning.
|
|
114
|
+
|
|
115
|
+
## Contributing
|
|
116
|
+
|
|
117
|
+
See [CONTRIBUTING.md](https://github.com/Nya-Foundation/nacho/blob/main/CONTRIBUTING.md).
|
|
118
|
+
Questions and bug reports go to the
|
|
119
|
+
[issue tracker](https://github.com/Nya-Foundation/nacho/issues) or the
|
|
120
|
+
[Nya Foundation Discord](https://discord.gg/jXAxVPSs7K).
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
[MIT](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
@@ -8,8 +8,9 @@ import ipaddress
|
|
|
8
8
|
import json
|
|
9
9
|
import logging
|
|
10
10
|
import sys
|
|
11
|
+
from collections.abc import Callable
|
|
11
12
|
from pathlib import Path
|
|
12
|
-
from typing import TYPE_CHECKING, Any
|
|
13
|
+
from typing import TYPE_CHECKING, Any
|
|
13
14
|
|
|
14
15
|
from nacho import HAS_REMOTE_DEPS, HAS_SCHEMA_DEPS, HAS_SERVER_DEPS
|
|
15
16
|
from nacho._version import __version__
|
|
@@ -47,7 +48,7 @@ def banner() -> str:
|
|
|
47
48
|
return f"{BANNER} Lightweight, self-hosted dynamic configuration · v{__version__}\n"
|
|
48
49
|
|
|
49
50
|
|
|
50
|
-
BUILT_IN_TEMPLATES = {
|
|
51
|
+
BUILT_IN_TEMPLATES: dict[str, dict[str, Any]] = {
|
|
51
52
|
"empty": {},
|
|
52
53
|
"web-app": {
|
|
53
54
|
"app": {"name": "web-app", "version": "1.0.0", "port": 3000},
|
|
@@ -108,21 +109,21 @@ def require_remote_deps() -> None:
|
|
|
108
109
|
raise ImportError("Remote features require: pip install nacho-python[remote]")
|
|
109
110
|
|
|
110
111
|
|
|
111
|
-
def build_client(args: argparse.Namespace, app_name:
|
|
112
|
+
def build_client(args: argparse.Namespace, app_name: str | None = None) -> "NachoClient":
|
|
112
113
|
"""Build the one NachoClient a command uses from --remote/--app-name/--api-key."""
|
|
113
114
|
require_remote_deps()
|
|
114
115
|
from nacho.client import NachoClient
|
|
115
116
|
|
|
116
117
|
return NachoClient(
|
|
117
118
|
args.remote,
|
|
118
|
-
app_name=app_name or getattr(args, "app_name", "default"
|
|
119
|
+
app_name=app_name or getattr(args, "app_name", None) or "default",
|
|
119
120
|
api_key=args.api_key,
|
|
120
121
|
)
|
|
121
122
|
|
|
122
123
|
|
|
123
124
|
def create_config(
|
|
124
|
-
config_path:
|
|
125
|
-
schema:
|
|
125
|
+
config_path: str | None = None,
|
|
126
|
+
schema: str | None = None,
|
|
126
127
|
read_only: bool = False,
|
|
127
128
|
) -> Nacho:
|
|
128
129
|
"""Create a Nacho instance for a local config file."""
|
|
@@ -670,7 +671,7 @@ def cmd_history_diff(args: argparse.Namespace) -> int:
|
|
|
670
671
|
schema_b = client.get_schema()
|
|
671
672
|
label_b = f"current (revision {revision})"
|
|
672
673
|
|
|
673
|
-
def as_lines(config: dict) ->
|
|
674
|
+
def as_lines(config: dict) -> list[str]:
|
|
674
675
|
return json.dumps(config, indent=2, sort_keys=True, ensure_ascii=False).splitlines()
|
|
675
676
|
|
|
676
677
|
diff = list(
|
|
@@ -729,7 +730,7 @@ def cmd_watch(args: argparse.Namespace) -> int:
|
|
|
729
730
|
# ---------------------------------------------------------------------------
|
|
730
731
|
# Entry point
|
|
731
732
|
# ---------------------------------------------------------------------------
|
|
732
|
-
def main_cli(argv:
|
|
733
|
+
def main_cli(argv: list[str] | None = None) -> int:
|
|
733
734
|
"""Main CLI entry point."""
|
|
734
735
|
parser = create_parser()
|
|
735
736
|
args = parser.parse_args(argv)
|
|
@@ -11,7 +11,7 @@ Requires the ``remote`` extra (``pip install nacho-python[remote]``).
|
|
|
11
11
|
|
|
12
12
|
from __future__ import annotations
|
|
13
13
|
|
|
14
|
-
from typing import Any
|
|
14
|
+
from typing import Any
|
|
15
15
|
from urllib.parse import quote
|
|
16
16
|
|
|
17
17
|
import requests
|
|
@@ -34,20 +34,20 @@ class NachoClient:
|
|
|
34
34
|
self,
|
|
35
35
|
url: str,
|
|
36
36
|
app_name: str = "default",
|
|
37
|
-
api_key:
|
|
37
|
+
api_key: str | None = None,
|
|
38
38
|
timeout: float = _DEFAULT_TIMEOUT,
|
|
39
39
|
) -> None:
|
|
40
40
|
self.base = url.rstrip("/")
|
|
41
41
|
self.app_name = app_name
|
|
42
42
|
self.api_key = api_key
|
|
43
43
|
self.timeout = timeout
|
|
44
|
-
self.last_generation:
|
|
44
|
+
self.last_generation: str | None = None
|
|
45
45
|
|
|
46
46
|
# ------------------------------------------------------------------
|
|
47
47
|
# Low-level request plumbing
|
|
48
48
|
# ------------------------------------------------------------------
|
|
49
49
|
|
|
50
|
-
def headers(self) ->
|
|
50
|
+
def headers(self) -> dict[str, str]:
|
|
51
51
|
if self.api_key:
|
|
52
52
|
return {"Authorization": f"Bearer {self.api_key}"}
|
|
53
53
|
return {}
|
|
@@ -57,9 +57,9 @@ class NachoClient:
|
|
|
57
57
|
method: str,
|
|
58
58
|
path: str,
|
|
59
59
|
*,
|
|
60
|
-
json_body:
|
|
61
|
-
params:
|
|
62
|
-
allowed:
|
|
60
|
+
json_body: dict[str, Any] | None = None,
|
|
61
|
+
params: dict[str, Any] | None = None,
|
|
62
|
+
allowed: tuple[int, ...] = (),
|
|
63
63
|
) -> requests.Response:
|
|
64
64
|
"""Perform a request; raise a typed error for any non-2xx status
|
|
65
65
|
not listed in *allowed*."""
|
|
@@ -119,7 +119,7 @@ class NachoClient:
|
|
|
119
119
|
self.last_generation = generation
|
|
120
120
|
|
|
121
121
|
@staticmethod
|
|
122
|
-
def _revision_from(resp: requests.Response) ->
|
|
122
|
+
def _revision_from(resp: requests.Response) -> int | None:
|
|
123
123
|
raw = resp.headers.get("X-Nacho-Revision")
|
|
124
124
|
return int(raw) if raw and raw.isdigit() else None
|
|
125
125
|
|
|
@@ -127,10 +127,10 @@ class NachoClient:
|
|
|
127
127
|
# System
|
|
128
128
|
# ------------------------------------------------------------------
|
|
129
129
|
|
|
130
|
-
def health(self) ->
|
|
130
|
+
def health(self) -> dict[str, Any]:
|
|
131
131
|
return self.request("GET", "/health").json()
|
|
132
132
|
|
|
133
|
-
def convert(self, data: Any, *, from_fmt: str, to_fmt: str) ->
|
|
133
|
+
def convert(self, data: Any, *, from_fmt: str, to_fmt: str) -> dict[str, Any]:
|
|
134
134
|
payload = {"data": data, "from": from_fmt, "to": to_fmt}
|
|
135
135
|
return self.request("POST", "/api/convert", json_body=payload).json()
|
|
136
136
|
|
|
@@ -138,19 +138,19 @@ class NachoClient:
|
|
|
138
138
|
# Apps
|
|
139
139
|
# ------------------------------------------------------------------
|
|
140
140
|
|
|
141
|
-
def list_apps(self) ->
|
|
141
|
+
def list_apps(self) -> dict[str, dict[str, Any]]:
|
|
142
142
|
return self.request("GET", "/api/apps").json()["data"]
|
|
143
143
|
|
|
144
144
|
def create_app(
|
|
145
145
|
self,
|
|
146
146
|
*,
|
|
147
|
-
data:
|
|
147
|
+
data: Any | None = None,
|
|
148
148
|
fmt: str = "json",
|
|
149
|
-
schema:
|
|
149
|
+
schema: Any | None = None,
|
|
150
150
|
schema_format: str = "json",
|
|
151
|
-
description:
|
|
152
|
-
) ->
|
|
153
|
-
payload:
|
|
151
|
+
description: str | None = None,
|
|
152
|
+
) -> dict[str, Any]:
|
|
153
|
+
payload: dict[str, Any] = {
|
|
154
154
|
"name": self.app_name,
|
|
155
155
|
"data": data if data is not None else {},
|
|
156
156
|
"format": fmt,
|
|
@@ -162,19 +162,19 @@ class NachoClient:
|
|
|
162
162
|
payload["description"] = description
|
|
163
163
|
return self.request("POST", "/api/apps", json_body=payload).json()
|
|
164
164
|
|
|
165
|
-
def get_app_info(self) ->
|
|
165
|
+
def get_app_info(self) -> dict[str, Any]:
|
|
166
166
|
return self.request("GET", self._app()).json()["data"]
|
|
167
167
|
|
|
168
|
-
def delete_app(self) ->
|
|
168
|
+
def delete_app(self) -> dict[str, Any]:
|
|
169
169
|
return self.request("DELETE", self._app()).json()
|
|
170
170
|
|
|
171
171
|
def update_metadata(
|
|
172
172
|
self,
|
|
173
173
|
*,
|
|
174
|
-
name:
|
|
175
|
-
description:
|
|
176
|
-
revision:
|
|
177
|
-
) ->
|
|
174
|
+
name: str | None = None,
|
|
175
|
+
description: str | None = None,
|
|
176
|
+
revision: int | None = None,
|
|
177
|
+
) -> dict[str, Any]:
|
|
178
178
|
payload = {
|
|
179
179
|
k: v
|
|
180
180
|
for k, v in (("name", name), ("description", description), ("revision", revision))
|
|
@@ -186,20 +186,20 @@ class NachoClient:
|
|
|
186
186
|
# Config
|
|
187
187
|
# ------------------------------------------------------------------
|
|
188
188
|
|
|
189
|
-
def get_config(self) ->
|
|
189
|
+
def get_config(self) -> tuple[dict[str, Any], int | None]:
|
|
190
190
|
resp = self.request("GET", self._app("/config"))
|
|
191
191
|
self._record_generation(resp)
|
|
192
192
|
return resp.json(), self._revision_from(resp)
|
|
193
193
|
|
|
194
194
|
def put_config(
|
|
195
|
-
self, data: Any, *, fmt: str = "json", revision:
|
|
196
|
-
) ->
|
|
197
|
-
payload:
|
|
195
|
+
self, data: Any, *, fmt: str = "json", revision: int | None = None
|
|
196
|
+
) -> dict[str, Any]:
|
|
197
|
+
payload: dict[str, Any] = {"data": data, "format": fmt}
|
|
198
198
|
if revision is not None:
|
|
199
199
|
payload["revision"] = revision
|
|
200
200
|
return self.request("PUT", self._app("/config"), json_body=payload).json()
|
|
201
201
|
|
|
202
|
-
def get_path(self, path: str) ->
|
|
202
|
+
def get_path(self, path: str) -> tuple[Any, int | None]:
|
|
203
203
|
resp = self.request("GET", self._app(f"/config/{quote(path, safe='')}"))
|
|
204
204
|
self._record_generation(resp)
|
|
205
205
|
return resp.json()["value"], self._revision_from(resp)
|
|
@@ -209,17 +209,17 @@ class NachoClient:
|
|
|
209
209
|
path: str,
|
|
210
210
|
value: Any,
|
|
211
211
|
*,
|
|
212
|
-
revision:
|
|
212
|
+
revision: int | None = None,
|
|
213
213
|
value_type: str = "raw",
|
|
214
|
-
) ->
|
|
215
|
-
payload:
|
|
214
|
+
) -> dict[str, Any]:
|
|
215
|
+
payload: dict[str, Any] = {"value": value, "type": value_type}
|
|
216
216
|
if revision is not None:
|
|
217
217
|
payload["revision"] = revision
|
|
218
218
|
return self.request(
|
|
219
219
|
"PUT", self._app(f"/config/{quote(path, safe='')}"), json_body=payload
|
|
220
220
|
).json()
|
|
221
221
|
|
|
222
|
-
def delete_path(self, path: str, *, revision:
|
|
222
|
+
def delete_path(self, path: str, *, revision: int | None = None) -> dict[str, Any]:
|
|
223
223
|
params = {"revision": revision} if revision is not None else None
|
|
224
224
|
return self.request(
|
|
225
225
|
"DELETE", self._app(f"/config/{quote(path, safe='')}"), params=params
|
|
@@ -229,22 +229,22 @@ class NachoClient:
|
|
|
229
229
|
# Schema
|
|
230
230
|
# ------------------------------------------------------------------
|
|
231
231
|
|
|
232
|
-
def get_schema(self) ->
|
|
232
|
+
def get_schema(self) -> dict[str, Any] | None:
|
|
233
233
|
return self.request("GET", self._app("/schema")).json()["data"]
|
|
234
234
|
|
|
235
235
|
def put_schema(
|
|
236
236
|
self,
|
|
237
|
-
schema:
|
|
237
|
+
schema: Any | None,
|
|
238
238
|
*,
|
|
239
239
|
fmt: str = "json",
|
|
240
|
-
revision:
|
|
241
|
-
) ->
|
|
242
|
-
payload:
|
|
240
|
+
revision: int | None = None,
|
|
241
|
+
) -> dict[str, Any]:
|
|
242
|
+
payload: dict[str, Any] = {"schema": schema, "schema_format": fmt}
|
|
243
243
|
if revision is not None:
|
|
244
244
|
payload["revision"] = revision
|
|
245
245
|
return self.request("PUT", self._app("/schema"), json_body=payload).json()
|
|
246
246
|
|
|
247
|
-
def validate(self, data: Any, *, fmt: str = "json") ->
|
|
247
|
+
def validate(self, data: Any, *, fmt: str = "json") -> dict[str, Any]:
|
|
248
248
|
payload = {"data": data, "format": fmt}
|
|
249
249
|
return self.request("POST", self._app("/validate"), json_body=payload).json()
|
|
250
250
|
|
|
@@ -252,14 +252,14 @@ class NachoClient:
|
|
|
252
252
|
# History
|
|
253
253
|
# ------------------------------------------------------------------
|
|
254
254
|
|
|
255
|
-
def list_history(self) ->
|
|
255
|
+
def list_history(self) -> list[dict[str, Any]]:
|
|
256
256
|
return self.request("GET", self._app("/history")).json()["data"]
|
|
257
257
|
|
|
258
|
-
def get_history_snapshot(self, revision: int) ->
|
|
258
|
+
def get_history_snapshot(self, revision: int) -> dict[str, Any]:
|
|
259
259
|
return self.request("GET", self._app(f"/history/{revision}")).json()["data"]
|
|
260
260
|
|
|
261
|
-
def rollback(self, revision: int, *, expected_revision:
|
|
262
|
-
payload:
|
|
261
|
+
def rollback(self, revision: int, *, expected_revision: int | None = None) -> dict[str, Any]:
|
|
262
|
+
payload: dict[str, Any] = {"revision": revision}
|
|
263
263
|
if expected_revision is not None:
|
|
264
264
|
payload["expected_revision"] = expected_revision
|
|
265
265
|
return self.request("POST", self._app("/rollback"), json_body=payload).json()
|