nacho-python 0.0.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-0.0.1/LICENSE +21 -0
- nacho_python-0.0.1/MANIFEST.in +3 -0
- nacho_python-0.0.1/PKG-INFO +605 -0
- nacho_python-0.0.1/README.md +560 -0
- nacho_python-0.0.1/nacho/__init__.py +39 -0
- nacho_python-0.0.1/nacho/_version.py +4 -0
- nacho_python-0.0.1/nacho/cli/__init__.py +11 -0
- nacho_python-0.0.1/nacho/cli/main.py +638 -0
- nacho_python-0.0.1/nacho/config.py +544 -0
- nacho_python-0.0.1/nacho/env.py +117 -0
- nacho_python-0.0.1/nacho/event.py +409 -0
- nacho_python-0.0.1/nacho/schema.py +121 -0
- nacho_python-0.0.1/nacho/server/__init__.py +35 -0
- nacho_python-0.0.1/nacho/server/app.py +515 -0
- nacho_python-0.0.1/nacho/server/auth.py +93 -0
- nacho_python-0.0.1/nacho/server/models.py +165 -0
- nacho_python-0.0.1/nacho/server/runtime.py +452 -0
- nacho_python-0.0.1/nacho/server/ui/index.html +1282 -0
- nacho_python-0.0.1/nacho/storage/__init__.py +27 -0
- nacho_python-0.0.1/nacho/storage/base.py +33 -0
- nacho_python-0.0.1/nacho/storage/file.py +40 -0
- nacho_python-0.0.1/nacho/storage/remote.py +293 -0
- nacho_python-0.0.1/nacho/utils/__init__.py +14 -0
- nacho_python-0.0.1/nacho/utils/io.py +143 -0
- nacho_python-0.0.1/nacho/utils/path.py +145 -0
- nacho_python-0.0.1/nacho_python.egg-info/PKG-INFO +605 -0
- nacho_python-0.0.1/nacho_python.egg-info/SOURCES.txt +52 -0
- nacho_python-0.0.1/nacho_python.egg-info/dependency_links.txt +1 -0
- nacho_python-0.0.1/nacho_python.egg-info/entry_points.txt +2 -0
- nacho_python-0.0.1/nacho_python.egg-info/requires.txt +33 -0
- nacho_python-0.0.1/nacho_python.egg-info/top_level.txt +1 -0
- nacho_python-0.0.1/pyproject.toml +146 -0
- nacho_python-0.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nya Foundation
|
|
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,605 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nacho-python
|
|
3
|
+
Version: 0.0.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 :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: pyyaml>=6.0
|
|
20
|
+
Requires-Dist: tomli>=2.0.0; python_version < "3.11"
|
|
21
|
+
Requires-Dist: tomli-w>=1.0.0
|
|
22
|
+
Provides-Extra: server
|
|
23
|
+
Requires-Dist: fastapi>=0.100.0; extra == "server"
|
|
24
|
+
Requires-Dist: uvicorn>=0.22.0; extra == "server"
|
|
25
|
+
Requires-Dist: websockets>=10.0; extra == "server"
|
|
26
|
+
Provides-Extra: remote
|
|
27
|
+
Requires-Dist: requests>=2.31.0; extra == "remote"
|
|
28
|
+
Requires-Dist: websocket-client>=1.8.0; extra == "remote"
|
|
29
|
+
Provides-Extra: schema
|
|
30
|
+
Requires-Dist: jsonschema>=4.0.0; extra == "schema"
|
|
31
|
+
Requires-Dist: rfc3987>=1.3.8; extra == "schema"
|
|
32
|
+
Provides-Extra: all
|
|
33
|
+
Requires-Dist: nacho-python[remote,schema,server]; extra == "all"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
38
|
+
Requires-Dist: httpx>=0.27.0; extra == "dev"
|
|
39
|
+
Requires-Dist: nacho-python[all]; extra == "dev"
|
|
40
|
+
Provides-Extra: lint
|
|
41
|
+
Requires-Dist: flake8>=6.0.0; extra == "lint"
|
|
42
|
+
Requires-Dist: black>=23.0.0; extra == "lint"
|
|
43
|
+
Requires-Dist: isort>=5.0.0; extra == "lint"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# Nacho
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
_ _ _ ____ _ _ ___
|
|
50
|
+
| \ | | / \ / ___|| | | | / _ \
|
|
51
|
+
| \| | / _ \ | | | |_| || | | |
|
|
52
|
+
| |\ | / ___ \ | |___ | _ || |_| |
|
|
53
|
+
|_| \_|/_/ \_\ \____||_| |_| \___/
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
<div align="center">
|
|
57
|
+
|
|
58
|
+
<h3>Lightweight, schema-first dynamic configuration service for Python.</h3>
|
|
59
|
+
|
|
60
|
+
<p>
|
|
61
|
+
<a href="README.md">English</a> |
|
|
62
|
+
<a href="README_zh.md">中文</a> |
|
|
63
|
+
<a href="README_ja.md">日本語</a>
|
|
64
|
+
</p>
|
|
65
|
+
|
|
66
|
+
<div>
|
|
67
|
+
<a href="https://pypi.org/project/nacho-python/"><img src="https://img.shields.io/pypi/v/nacho-python.svg" alt="PyPI version"/></a>
|
|
68
|
+
<a href="https://pypi.org/project/nacho-python/"><img src="https://img.shields.io/pypi/pyversions/nacho-python.svg" alt="Python versions"/></a>
|
|
69
|
+
<a href="https://github.com/nya-foundation/nacho/blob/main/LICENSE"><img src="https://img.shields.io/github/license/nya-foundation/nacho.svg" alt="License"/></a>
|
|
70
|
+
<a href="https://pepy.tech/projects/nacho-python"><img src="https://static.pepy.tech/badge/nacho-python" alt="PyPI Downloads"/></a>
|
|
71
|
+
<a href="https://hub.docker.com/r/k3scat/nacho"><img src="https://img.shields.io/docker/pulls/k3scat/nacho" alt="Docker Pulls"/></a>
|
|
72
|
+
<a href="https://deepwiki.com/Nya-Foundation/Nacho"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"/></a>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div>
|
|
76
|
+
<a href="https://codecov.io/gh/nya-foundation/nacho"><img src="https://codecov.io/gh/nya-foundation/nacho/branch/main/graph/badge.svg" alt="Code Coverage"/></a>
|
|
77
|
+
<a href="https://github.com/nya-foundation/nacho/actions/workflows/scan.yml"><img src="https://github.com/nya-foundation/nacho/actions/workflows/scan.yml/badge.svg" alt="CodeQL & Dependencies Scan"/></a>
|
|
78
|
+
<a href="https://github.com/nya-foundation/nacho/actions/workflows/publish.yml"><img src="https://github.com/nya-foundation/nacho/actions/workflows/publish.yml/badge.svg" alt="CI/CD Builds"/></a>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
> **Note:** This project is under active development. If you encounter unexpected behavior, please open an issue on GitHub.
|
|
83
|
+
|
|
84
|
+
## What is Nacho?
|
|
85
|
+
|
|
86
|
+
Nacho is a schema-first dynamic configuration service for Python applications.
|
|
87
|
+
It handles YAML, JSON, and TOML configuration files and provides a consistent API across local files, in-memory dicts, and remote configuration servers.
|
|
88
|
+
|
|
89
|
+
| Feature | Description |
|
|
90
|
+
|---|---|
|
|
91
|
+
| **Multi-format support** | Read and write YAML, JSON, and TOML with a unified API. |
|
|
92
|
+
| **Schema-first validation** | Validate every write against a JSON Schema — invalid data is rejected before it reaches storage. |
|
|
93
|
+
| **Event system** | Register handlers that fire on specific configuration changes, keyed by dot-notation path patterns. |
|
|
94
|
+
| **Environment overrides** | Overlay environment variables at runtime without writing them back to storage. |
|
|
95
|
+
| **Remote configuration** | Connect to a Nacho API server for centralized configuration and optional WebSocket push. |
|
|
96
|
+
| **Thread safe** | All read/write operations are protected by a reentrant lock. |
|
|
97
|
+
| **Pluggable storage** | Swap in file, in-memory, or remote backends without changing application code. |
|
|
98
|
+
|
|
99
|
+
## Prerequisites
|
|
100
|
+
|
|
101
|
+
- Python 3.9 or higher
|
|
102
|
+
- Docker (optional, for containerized deployment)
|
|
103
|
+
|
|
104
|
+
## Installation
|
|
105
|
+
|
|
106
|
+
Nacho uses optional extras to keep the core dependency footprint small.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Core — local file management only
|
|
110
|
+
pip install nacho-python
|
|
111
|
+
|
|
112
|
+
# With web server and REST API
|
|
113
|
+
pip install nacho-python[server]
|
|
114
|
+
|
|
115
|
+
# With JSON Schema validation
|
|
116
|
+
pip install nacho-python[schema]
|
|
117
|
+
|
|
118
|
+
# With remote client
|
|
119
|
+
pip install nacho-python[remote]
|
|
120
|
+
|
|
121
|
+
# Everything
|
|
122
|
+
pip install nacho-python[all]
|
|
123
|
+
|
|
124
|
+
# Development and testing
|
|
125
|
+
pip install nacho-python[dev]
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
| Extra | Dependencies | Purpose |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| *(none)* | pyyaml, tomli-w | Local file read/write (YAML, JSON, TOML) |
|
|
131
|
+
| `server` | fastapi, uvicorn, websockets | REST API and WebSocket watch server |
|
|
132
|
+
| `schema` | jsonschema, rfc3987 | JSON Schema validation on writes |
|
|
133
|
+
| `remote` | requests, websocket-client | Remote configuration client |
|
|
134
|
+
| `all` | All of the above | Complete installation |
|
|
135
|
+
| `dev` | pytest, httpx, coverage | Development and testing |
|
|
136
|
+
|
|
137
|
+
## Quick Start
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from nacho import Nacho
|
|
141
|
+
|
|
142
|
+
# File-backed configuration (file is created if it does not exist)
|
|
143
|
+
config = Nacho("config.yaml", events=True)
|
|
144
|
+
|
|
145
|
+
# Register a handler that fires when any key under "database" changes
|
|
146
|
+
@config.on_change("database.*")
|
|
147
|
+
def on_db_change(path, old_value, new_value, **kwargs):
|
|
148
|
+
print(f"{path}: {old_value} -> {new_value}")
|
|
149
|
+
|
|
150
|
+
# Read values with dot-notation keys
|
|
151
|
+
host = config.get("database.host", default="localhost")
|
|
152
|
+
port = config.get_int("database.port", default=5432)
|
|
153
|
+
|
|
154
|
+
# Write values — triggers registered handlers
|
|
155
|
+
config.set("database.pool_size", 10)
|
|
156
|
+
|
|
157
|
+
# Persist to disk
|
|
158
|
+
config.save()
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Configuration Management
|
|
162
|
+
|
|
163
|
+
Nacho accepts a file path, a dict, or an explicit storage backend.
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from nacho import Nacho
|
|
167
|
+
|
|
168
|
+
# In-memory with initial data
|
|
169
|
+
config = Nacho({"database": {"host": "127.0.0.1", "port": 5432}})
|
|
170
|
+
|
|
171
|
+
# File-backed
|
|
172
|
+
config = Nacho("config.yaml")
|
|
173
|
+
|
|
174
|
+
# Read with type coercion
|
|
175
|
+
host = config.get("database.host") # str
|
|
176
|
+
port = config.get_int("database.port") # int
|
|
177
|
+
debug = config.get_bool("app.debug") # bool
|
|
178
|
+
tags = config.get_list("app.tags") # list
|
|
179
|
+
options = config.get_dict("app.options") # dict
|
|
180
|
+
|
|
181
|
+
# Deep-merge additional keys (does not remove existing keys)
|
|
182
|
+
config.update({"logging": {"level": "DEBUG"}})
|
|
183
|
+
|
|
184
|
+
# Replace the entire config
|
|
185
|
+
config.replace({"database": {"host": "prod-db", "port": 5432}})
|
|
186
|
+
|
|
187
|
+
# Delete a key
|
|
188
|
+
config.delete("legacy.setting")
|
|
189
|
+
|
|
190
|
+
# Reload from storage and re-apply env overrides
|
|
191
|
+
config.reload()
|
|
192
|
+
|
|
193
|
+
# Export current config as a JSON string
|
|
194
|
+
print(config.json())
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Atomic transactions
|
|
198
|
+
|
|
199
|
+
Group multiple writes into a single atomic operation. The transaction commits when the block exits cleanly; it is discarded on any exception.
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
with config.transaction() as txn:
|
|
203
|
+
txn.set("database.host", "new-host")
|
|
204
|
+
txn.set("database.port", 5433)
|
|
205
|
+
# Handlers fire once here with the aggregated changes
|
|
206
|
+
config.save()
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Environment Variable Overrides
|
|
210
|
+
|
|
211
|
+
Pass `env_prefix` to apply environment variables on top of the configuration at load time. Variable names follow the pattern `{PREFIX}_{NESTED_KEY}`, with nested levels separated by the delimiter (default: `_`).
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
export MYAPP_DATABASE_HOST=prod-db.example.com
|
|
215
|
+
export MYAPP_DATABASE_PORT=5433
|
|
216
|
+
export MYAPP_FEATURES_ENABLED=true
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
config = Nacho(
|
|
221
|
+
"config.yaml",
|
|
222
|
+
env_prefix="MYAPP",
|
|
223
|
+
env_delimiter="_",
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
config.get("database.host") # "prod-db.example.com"
|
|
227
|
+
config.get_int("database.port") # 5433
|
|
228
|
+
config.get_bool("features.enabled") # True
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Environment values are coerced to bool, int, float, or JSON objects where possible, and fall back to string otherwise. Env overrides are runtime-only overlays: `save()` persists the stored config, not the effective env-overlaid values.
|
|
232
|
+
|
|
233
|
+
## Event System
|
|
234
|
+
|
|
235
|
+
The event system dispatches change notifications after every successful write. Events carry the changed path, old value, new value, and event type.
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from nacho import Nacho, EventType
|
|
239
|
+
|
|
240
|
+
config = Nacho("config.yaml", events=True)
|
|
241
|
+
|
|
242
|
+
# Fires for any change to a key under "database"
|
|
243
|
+
@config.on_change("database.*")
|
|
244
|
+
def on_db_change(path, old_value, new_value, **kwargs):
|
|
245
|
+
print(f"database key changed: {path}")
|
|
246
|
+
|
|
247
|
+
# Fires once per write operation (aggregate event), regardless of which key changed
|
|
248
|
+
@config.on_change("@global")
|
|
249
|
+
def on_any_change(**kwargs):
|
|
250
|
+
print("config was modified")
|
|
251
|
+
|
|
252
|
+
# Fires for CREATE or UPDATE events under "cache"
|
|
253
|
+
@config.on_event([EventType.CREATE, EventType.UPDATE], path_pattern="cache.*")
|
|
254
|
+
def on_cache_change(event_type, path, new_value, **kwargs):
|
|
255
|
+
print(f"{event_type.name} {path} = {new_value}")
|
|
256
|
+
|
|
257
|
+
config.set("database.host", "new-host") # triggers on_db_change, on_any_change
|
|
258
|
+
config.set("cache.ttl", 600) # triggers on_cache_change (CREATE)
|
|
259
|
+
config.set("cache.ttl", 300) # triggers on_cache_change (UPDATE)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Path pattern reference:**
|
|
263
|
+
|
|
264
|
+
| Pattern | Fires when |
|
|
265
|
+
|---|---|
|
|
266
|
+
| `None` (default) | Any change at any path |
|
|
267
|
+
| `"@global"` | Once per write operation (aggregate) |
|
|
268
|
+
| `"*"` | Any per-key event (not aggregate) |
|
|
269
|
+
| `"database.*"` | Any key nested under `database` |
|
|
270
|
+
|
|
271
|
+
Handlers may be sync or async. Async handlers are scheduled on the running event loop when one exists, or run via `asyncio.run()` otherwise.
|
|
272
|
+
|
|
273
|
+
## Schema Validation
|
|
274
|
+
|
|
275
|
+
Nacho enforces schema on every write. An invalid value raises `ValidationError` before the change is applied — the configuration is never left in an invalid state.
|
|
276
|
+
|
|
277
|
+
Requires `pip install nacho-python[schema]`.
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
// schema.json
|
|
281
|
+
{
|
|
282
|
+
"type": "object",
|
|
283
|
+
"properties": {
|
|
284
|
+
"database": {
|
|
285
|
+
"type": "object",
|
|
286
|
+
"required": ["host", "port"],
|
|
287
|
+
"properties": {
|
|
288
|
+
"host": {"type": "string"},
|
|
289
|
+
"port": {"type": "integer", "minimum": 1024}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
"required": ["database"]
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
from nacho import Nacho, ValidationError
|
|
299
|
+
|
|
300
|
+
config = Nacho("config.yaml", schema="schema.json")
|
|
301
|
+
|
|
302
|
+
# Invalid write raises immediately — config is not modified
|
|
303
|
+
try:
|
|
304
|
+
config.set("database.port", "not-a-number")
|
|
305
|
+
except ValidationError as e:
|
|
306
|
+
print(e.errors) # list of violation strings
|
|
307
|
+
|
|
308
|
+
# Inspect the current config against the schema without writing
|
|
309
|
+
errors = config.validate()
|
|
310
|
+
if errors:
|
|
311
|
+
print("Current config has violations:", errors)
|
|
312
|
+
|
|
313
|
+
# Validate an arbitrary dict against the schema
|
|
314
|
+
errors = config.check({"database": {"host": "localhost", "port": 80}})
|
|
315
|
+
print(errors) # ["port must be >= 1024"]
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Remote Configuration
|
|
319
|
+
|
|
320
|
+
Connect to a Nacho server and optionally receive real-time updates over WebSocket. The client writes through the REST API; the server can push changes back over WebSocket.
|
|
321
|
+
|
|
322
|
+
Requires `pip install nacho-python[remote]`.
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
from nacho import Nacho, RemoteStorageBackend
|
|
326
|
+
|
|
327
|
+
storage = RemoteStorageBackend(
|
|
328
|
+
url="https://config-server.example.com",
|
|
329
|
+
app_name="my-service",
|
|
330
|
+
api_key="secure-key",
|
|
331
|
+
watch=True, # opt in to WebSocket updates
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
config = Nacho(storage=storage, events=True)
|
|
335
|
+
|
|
336
|
+
# The API is identical to file-backed usage
|
|
337
|
+
host = config.get("database.host")
|
|
338
|
+
|
|
339
|
+
# Handlers fire on changes pushed from the server
|
|
340
|
+
@config.on_change("features.*")
|
|
341
|
+
def on_feature_change(path, new_value, **kwargs):
|
|
342
|
+
print(f"feature flag updated: {path} = {new_value}")
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## REST API Server
|
|
346
|
+
|
|
347
|
+
`NachoOrchestrator` wraps one or more `Nacho` instances in a FastAPI application.
|
|
348
|
+
The server is API-first: use `/docs` for interactive OpenAPI documentation, `/ws/{app}` for live config updates, and `/ui` for the built-in management UI.
|
|
349
|
+
|
|
350
|
+
Requires `pip install nacho-python[server]`.
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
from nacho import Nacho, NachoOrchestrator
|
|
354
|
+
|
|
355
|
+
apps = {
|
|
356
|
+
"my-service": Nacho("config.yaml", events=True),
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
server = NachoOrchestrator(
|
|
360
|
+
apps=apps,
|
|
361
|
+
api_key="secure-key",
|
|
362
|
+
cors_origins=["https://admin.example.com"],
|
|
363
|
+
)
|
|
364
|
+
server.run(host="0.0.0.0", port=8000)
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Management UI
|
|
368
|
+
|
|
369
|
+
Nacho ships a built-in web UI for managing apps, configurations, and schemas.
|
|
370
|
+
Once the server is running it is available at `/ui` — there is no separate
|
|
371
|
+
process or build step; the page is a single file served directly by FastAPI.
|
|
372
|
+
|
|
373
|
+
The UI supports:
|
|
374
|
+
|
|
375
|
+
- **App management** — list, create, rename, describe, and delete apps.
|
|
376
|
+
- **Configuration editing** — a code editor for JSON, YAML, and TOML with
|
|
377
|
+
syntax highlighting, one-click format switching, on-demand validation, and
|
|
378
|
+
revision-aware saves (a stale write surfaces a conflict instead of
|
|
379
|
+
clobbering newer data).
|
|
380
|
+
- **Schema editing** — view, edit, or clear an app's JSON Schema after
|
|
381
|
+
creation, in JSON, YAML, or TOML; the current configuration is re-checked
|
|
382
|
+
against the new schema.
|
|
383
|
+
- **Live updates** — changes pushed over WebSocket are reflected in real time.
|
|
384
|
+
|
|
385
|
+
When the server is started with `--api-key`, the UI prompts for the key on
|
|
386
|
+
first load and remembers it in the browser. The `/ui` page itself is public so
|
|
387
|
+
the sign-in screen can load; every API call behind it stays authenticated.
|
|
388
|
+
|
|
389
|
+
### Mounting into an existing FastAPI application
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
from fastapi import FastAPI
|
|
393
|
+
from nacho import Nacho, NachoOrchestrator
|
|
394
|
+
|
|
395
|
+
app = FastAPI(title="My Application")
|
|
396
|
+
|
|
397
|
+
orchestrator = NachoOrchestrator(
|
|
398
|
+
apps={"config": Nacho("config.yaml", events=True)},
|
|
399
|
+
api_key="secure-key",
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
# Configuration API available under /config
|
|
403
|
+
app.mount("/config", orchestrator.app)
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
Interactive API documentation is available at `/docs` (Swagger) and `/redoc` once the server is running.
|
|
407
|
+
|
|
408
|
+
### API write format and revisions
|
|
409
|
+
|
|
410
|
+
The API accepts native JSON objects for config and schema payloads:
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
curl -X POST http://localhost:8000/api/apps \
|
|
414
|
+
-H "Authorization: Bearer secure-key" \
|
|
415
|
+
-H "Content-Type: application/json" \
|
|
416
|
+
-d '{
|
|
417
|
+
"name": "my-service",
|
|
418
|
+
"data": {"database": {"host": "localhost", "port": 5432}},
|
|
419
|
+
"schema": {
|
|
420
|
+
"type": "object",
|
|
421
|
+
"properties": {
|
|
422
|
+
"database": {"type": "object"}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}'
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
The older encoded-string format is still supported for JSON, YAML, and TOML:
|
|
429
|
+
|
|
430
|
+
```json
|
|
431
|
+
{"data": "{\"feature\": true}", "format": "json"}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Full-config reads return `ETag` and `X-Nacho-Revision`. Writes can include either `If-Match: "<revision>"` or a JSON `revision` field. If the server has moved ahead, the write returns `409 Conflict` and leaves the config unchanged.
|
|
435
|
+
|
|
436
|
+
```bash
|
|
437
|
+
curl http://localhost:8000/api/apps/my-service/config \
|
|
438
|
+
-H "Authorization: Bearer secure-key" \
|
|
439
|
+
-i
|
|
440
|
+
|
|
441
|
+
curl -X PUT http://localhost:8000/api/apps/my-service/config/cache.ttl \
|
|
442
|
+
-H "Authorization: Bearer secure-key" \
|
|
443
|
+
-H "If-Match: \"3\"" \
|
|
444
|
+
-H "Content-Type: application/json" \
|
|
445
|
+
-d '{"value": 600}'
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### API reference
|
|
449
|
+
|
|
450
|
+
**System**
|
|
451
|
+
|
|
452
|
+
| Endpoint | Method | Description |
|
|
453
|
+
|---|---|---|
|
|
454
|
+
| `/health` | GET | Health check and instance summary |
|
|
455
|
+
| `/ui` | GET | Built-in web management UI |
|
|
456
|
+
| `/api/convert` | POST | Convert a payload between JSON, YAML, and TOML |
|
|
457
|
+
|
|
458
|
+
**App management**
|
|
459
|
+
|
|
460
|
+
| Endpoint | Method | Description |
|
|
461
|
+
|---|---|---|
|
|
462
|
+
| `/api/apps` | GET | List all apps |
|
|
463
|
+
| `/api/apps` | POST | Create a new app |
|
|
464
|
+
| `/api/apps/{app}` | GET | Get app info |
|
|
465
|
+
| `/api/apps/{app}` | PUT | Replace app config and metadata |
|
|
466
|
+
| `/api/apps/{app}` | DELETE | Delete an app |
|
|
467
|
+
| `/api/apps/{app}/metadata` | PATCH | Update app name or description |
|
|
468
|
+
|
|
469
|
+
**Configuration**
|
|
470
|
+
|
|
471
|
+
| Endpoint | Method | Description |
|
|
472
|
+
|---|---|---|
|
|
473
|
+
| `/api/apps/{app}/config` | GET | Get full configuration |
|
|
474
|
+
| `/api/apps/{app}/config` | PUT | Replace full configuration |
|
|
475
|
+
| `/api/apps/{app}/config/{path}` | GET | Get value at path |
|
|
476
|
+
| `/api/apps/{app}/config/{path}` | PUT | Set value at path |
|
|
477
|
+
| `/api/apps/{app}/config/{path}` | DELETE | Delete key at path |
|
|
478
|
+
| `/api/apps/{app}/schema` | GET | Get the app's JSON Schema |
|
|
479
|
+
| `/api/apps/{app}/schema` | PUT | Replace or clear the app's JSON Schema |
|
|
480
|
+
| `/api/apps/{app}/validate` | POST | Validate a config payload against the schema |
|
|
481
|
+
|
|
482
|
+
**Real-time**
|
|
483
|
+
|
|
484
|
+
| Endpoint | Protocol | Description |
|
|
485
|
+
|---|---|---|
|
|
486
|
+
| `/ws/{app}` | WebSocket | Receive configuration change events |
|
|
487
|
+
|
|
488
|
+
## Command-Line Interface
|
|
489
|
+
|
|
490
|
+
```bash
|
|
491
|
+
nacho --help
|
|
492
|
+
nacho --version
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### Server
|
|
496
|
+
|
|
497
|
+
```bash
|
|
498
|
+
nacho server \
|
|
499
|
+
--config config.yaml \
|
|
500
|
+
--schema schema.json \
|
|
501
|
+
--host 0.0.0.0 \
|
|
502
|
+
--port 8000 \
|
|
503
|
+
--api-key "secure-key" \
|
|
504
|
+
--app-name "my-service" \
|
|
505
|
+
--data-dir ".nacho/apps" \
|
|
506
|
+
--event true \
|
|
507
|
+
--read-only false
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### Local configuration
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
# Create a new config from a template
|
|
514
|
+
nacho init config.yaml --template default
|
|
515
|
+
|
|
516
|
+
# Available templates: empty, default, web-app, api-service, microservice
|
|
517
|
+
|
|
518
|
+
# Read
|
|
519
|
+
nacho get database.host --config config.yaml
|
|
520
|
+
nacho get --config config.yaml --format json
|
|
521
|
+
|
|
522
|
+
# Write
|
|
523
|
+
nacho set database.port 5432 --config config.yaml
|
|
524
|
+
|
|
525
|
+
# Delete
|
|
526
|
+
nacho delete legacy.setting --config config.yaml
|
|
527
|
+
|
|
528
|
+
# Validate against schema
|
|
529
|
+
nacho validate --config config.yaml --schema schema.json
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### Remote
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
nacho get database.host \
|
|
536
|
+
--remote http://config-server:8000 \
|
|
537
|
+
--app-name my-service \
|
|
538
|
+
--api-key "secure-key"
|
|
539
|
+
|
|
540
|
+
# Read full config and include the current remote revision
|
|
541
|
+
nacho get \
|
|
542
|
+
--remote http://config-server:8000 \
|
|
543
|
+
--app-name my-service \
|
|
544
|
+
--api-key "secure-key" \
|
|
545
|
+
--format json \
|
|
546
|
+
--show-revision
|
|
547
|
+
|
|
548
|
+
nacho set cache.ttl 600 \
|
|
549
|
+
--remote http://config-server:8000 \
|
|
550
|
+
--app-name my-service \
|
|
551
|
+
--api-key "secure-key" \
|
|
552
|
+
--revision 3
|
|
553
|
+
|
|
554
|
+
nacho delete legacy.setting \
|
|
555
|
+
--remote http://config-server:8000 \
|
|
556
|
+
--app-name my-service \
|
|
557
|
+
--api-key "secure-key" \
|
|
558
|
+
--revision 4
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
## Docker
|
|
562
|
+
|
|
563
|
+
Nacho ships a multi-stage `Dockerfile` that builds a small Alpine-based image
|
|
564
|
+
running the REST API server.
|
|
565
|
+
|
|
566
|
+
```bash
|
|
567
|
+
# Build the image
|
|
568
|
+
docker build -t nacho .
|
|
569
|
+
|
|
570
|
+
# Run the server (UI at http://localhost:8000/ui)
|
|
571
|
+
docker run -p 8000:8000 nacho
|
|
572
|
+
|
|
573
|
+
# Run with authentication enabled
|
|
574
|
+
docker run -p 8000:8000 nacho \
|
|
575
|
+
nacho server --config config.yaml --api-key "secure-key"
|
|
576
|
+
|
|
577
|
+
# Mount your own config for the default app
|
|
578
|
+
docker run -p 8000:8000 \
|
|
579
|
+
-v "$(pwd)/config.yaml:/app/config.yaml" nacho
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
Or use `docker-compose`:
|
|
583
|
+
|
|
584
|
+
```bash
|
|
585
|
+
docker compose up --build
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
The image entrypoint is `nacho`, and the default command is
|
|
589
|
+
`server --config config.yaml`. Append any `nacho server` flags
|
|
590
|
+
(`--api-key`, `--read-only`, `--event`, …) to override the defaults. The
|
|
591
|
+
container exposes port `8000` and runs as a non-root user.
|
|
592
|
+
|
|
593
|
+
## Current Limits
|
|
594
|
+
|
|
595
|
+
- Dot-notation paths are intentionally simple. Literal dots in key names and numeric string keys are ambiguous; prefer nested object keys for now.
|
|
596
|
+
- The built-in API key auth is suitable for local, private, or single-tenant deployments. Shared production deployments should add scoped tokens, audit logs, and rate limits in front of the service.
|
|
597
|
+
- File-backed server state is best for development and small single-process deployments. Use the storage abstraction as the boundary for a stronger durable backend when you need multi-process or high-availability operation.
|
|
598
|
+
|
|
599
|
+
## Community
|
|
600
|
+
|
|
601
|
+
Need help? Open an issue on [GitHub](https://github.com/nya-foundation/nacho/issues) or join the [Nya Foundation Discord](https://discord.gg/jXAxVPSs7K).
|
|
602
|
+
|
|
603
|
+
## License
|
|
604
|
+
|
|
605
|
+
MIT — see [LICENSE](LICENSE) for details.
|