kikolib 0.3.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.
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .venv/
5
+ venv/
6
+ *.o
7
+ *.so
8
+ *.exe
9
+ CMakeCache.txt
10
+ CMakeFiles/
11
+ build/
12
+ dist/
13
+ *.deb
@@ -0,0 +1,38 @@
1
+ # kikolib changes
2
+
3
+ ## 0.3.1 - code-smell cleanup, no behaviour change
4
+
5
+ SonarQube findings fixed without changing behaviour or API: `logger.exception` instead of
6
+ `logger.error(..., exc_info=True)`; duplicated literals in `server` and `config` became module constants;
7
+ redundant exception classes dropped (`binascii.Error`, `BlockingIOError` were already caught as their
8
+ parents); unused `cur` in `tomlwrite._apply` and the unused `method` argument of the private `http._wrap`
9
+ removed; `sse` merges a nested `if`. Deliberate patterns (catching `BaseException` to release a connection
10
+ before raising a mapped error, interface signatures with unused arguments) carry a `NOSONAR` reason.
11
+
12
+ Packaging (no code change): the folder also carries `pyproject.toml` (hatchling, build-time only),
13
+ `README-PYPI.md` and `LICENSE`, so `pip install kikolib` from PyPI is possible; the wheel ships only the
14
+ modules, `README.md` and `CHANGES.md`. Copy-the-folder consumers are unaffected (re-run the manifest check
15
+ after re-copying). Publishing: `docs/PUBLISHING-KIKOLIB.md`.
16
+
17
+ ## 0.3.0 - yaml_lite leaves kikolib
18
+
19
+ `yaml_lite` is removed from kikolib (a YAML reader does not belong in the shared base). kiko-lite keeps the
20
+ code as its own private module `kiko_lite/yaml_lite.py` (needed by `kiko import` of an old kiko.yaml and by
21
+ the models/keys exchange reader). Breaking for any consumer that does `from kikolib import yaml_lite`: it must
22
+ carry its own copy (rex does: config.py, sources.py, orchestrator/policy.py). No other module changed.
23
+ Considered and kept after checking consumers: websocket (used by spy), winhttp (Windows default; switch
24
+ `KIKO_HTTP_IMPL=stdlib`), dcop keystore backend (TDE), tomlwrite, server watchdog / RSS limit / drain.
25
+
26
+ ## 0.2.1 - lingering close reads up to 1 MiB
27
+
28
+ `server.LINGER_BYTES` 64 KiB -> 1 MiB. A request rejected early (403/415/411) with a body larger than the cap
29
+ was closed with unread data, and on macOS (smaller loopback buffers) that RST destroyed the answer before the
30
+ client read it. The close is still bounded in time (1 s) and runs per connection thread.
31
+
32
+ ## 0.2.0 - first pinned release
33
+
34
+ First release meant to be copied unmodified into other projects (see README, "How other projects take
35
+ kikolib"). Ships `SHA256SUMS`. Version 0.1.0 was an unreleased stamp and is ambiguous; do not use it.
36
+
37
+ Modules: config, dotenv, factory, http, keystore, logs, posix, retry, server, sse, tokens, tomlwrite,
38
+ websocket, winhttp, yaml_lite.
kikolib-0.3.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Peter Kokosharov <peter.kokosharov@gmail.com>
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.
kikolib-0.3.1/PKG-INFO ADDED
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.5
2
+ Name: kikolib
3
+ Version: 0.3.1
4
+ Summary: Standard-library-only toolkit for small Python servers: threaded HTTP server, pooled HTTP client, SSE, WebSocket, TOML writer, .env, OS secret stores.
5
+ Project-URL: Homepage, https://github.com/peterkokosharov/kiko
6
+ Project-URL: Documentation, https://github.com/peterkokosharov/kiko/blob/main/docs/gateway/kikolib/USER-GUIDE.md
7
+ Project-URL: Changelog, https://github.com/peterkokosharov/kiko/blob/main/gateway/kikolib/CHANGES.md
8
+ Project-URL: Source, https://github.com/peterkokosharov/kiko/tree/main/gateway/kikolib
9
+ Project-URL: Issues, https://github.com/peterkokosharov/kiko/issues
10
+ Project-URL: Discussions, https://github.com/peterkokosharov/kiko/discussions
11
+ Author-email: Peter Kokosharov <peter.kokosharov@gmail.com>
12
+ License-Expression: MIT
13
+ License-File: LICENSE
14
+ Keywords: dotenv,http,keyring,server,sse,stdlib,threads,toml,websocket
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Operating System :: POSIX :: Linux
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
28
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
29
+ Requires-Python: >=3.11
30
+ Description-Content-Type: text/markdown
31
+
32
+ # kikolib
33
+
34
+ The standard library for small servers: plain Python modules that give a program what the standard library
35
+ leaves out when you write a small server or service.
36
+
37
+ - Threaded HTTP server with a router, an HTTP client with a connection pool and retry
38
+ - Server-Sent Events, WebSocket, TOML writing, `.env` files, OS secret stores, a plug-in factory
39
+ - **Standard library only, zero dependencies.** Threads, no asyncio. Python 3.11 or newer.
40
+ - Linux, Windows and macOS. Small enough to read in an afternoon.
41
+
42
+ ## Install
43
+
44
+ ```
45
+ pip install kikolib
46
+ ```
47
+
48
+ ```python
49
+ import kikolib
50
+ print(kikolib.__version__)
51
+ ```
52
+
53
+ ## Documentation
54
+
55
+ User guide with runnable demos:
56
+ https://github.com/peterkokosharov/kiko/blob/main/docs/gateway/kikolib/USER-GUIDE.md
57
+
58
+ Changes: https://github.com/peterkokosharov/kiko/blob/main/gateway/kikolib/CHANGES.md
59
+
60
+ Public API: names without a leading underscore. While the version is 0.x, a minor release may break it
61
+ (every break is listed in CHANGES.md); patch releases do not.
62
+
63
+ ## License and support
64
+
65
+ MIT: free to use, change, cut and sell in your products. Keep the LICENSE text (copyright and permission
66
+ notice) with every copy.
67
+
68
+ Optional, not a condition: if it helps you, mention where it came from.
69
+
70
+ If something does not work or you do not like it, post in the forum (GitHub Discussions / Issues at
71
+ https://github.com/peterkokosharov/kiko); the author will try to fix it. No warranty.
@@ -0,0 +1,40 @@
1
+ # kikolib
2
+
3
+ The standard library for small servers: plain Python modules that give a program what the standard library
4
+ leaves out when you write a small server or service.
5
+
6
+ - Threaded HTTP server with a router, an HTTP client with a connection pool and retry
7
+ - Server-Sent Events, WebSocket, TOML writing, `.env` files, OS secret stores, a plug-in factory
8
+ - **Standard library only, zero dependencies.** Threads, no asyncio. Python 3.11 or newer.
9
+ - Linux, Windows and macOS. Small enough to read in an afternoon.
10
+
11
+ ## Install
12
+
13
+ ```
14
+ pip install kikolib
15
+ ```
16
+
17
+ ```python
18
+ import kikolib
19
+ print(kikolib.__version__)
20
+ ```
21
+
22
+ ## Documentation
23
+
24
+ User guide with runnable demos:
25
+ https://github.com/peterkokosharov/kiko/blob/main/docs/gateway/kikolib/USER-GUIDE.md
26
+
27
+ Changes: https://github.com/peterkokosharov/kiko/blob/main/gateway/kikolib/CHANGES.md
28
+
29
+ Public API: names without a leading underscore. While the version is 0.x, a minor release may break it
30
+ (every break is listed in CHANGES.md); patch releases do not.
31
+
32
+ ## License and support
33
+
34
+ MIT: free to use, change, cut and sell in your products. Keep the LICENSE text (copyright and permission
35
+ notice) with every copy.
36
+
37
+ Optional, not a condition: if it helps you, mention where it came from.
38
+
39
+ If something does not work or you do not like it, post in the forum (GitHub Discussions / Issues at
40
+ https://github.com/peterkokosharov/kiko); the author will try to fix it. No warranty.
@@ -0,0 +1,83 @@
1
+ # kikolib
2
+
3
+ Small, standard-library-only library for kiko-lite (a stdlib proxy so Claude Code can talk to
4
+ NVIDIA / Groq / Gemini / Qwen / OpenAI). Version 0.3.1. Python >= 3.11 (import fails earlier).
5
+ Primary target Linux (Debian 12, Q4OS, Mint); Windows also works (launcher `kiko-lite.cmd`).
6
+
7
+ The wider role of kikolib as a shared base for kiko, rex, kircho and an agent system is described in
8
+ [`docs/STDLIB-2.md`](../../docs/STDLIB-2.md) (proposal, 2026-11-22).
9
+
10
+ ## Rules
11
+
12
+ 1. **Standard library only.** A module imports only the stdlib and other kikolib modules.
13
+ 2. **Threads, no asyncio.** No module uses asyncio (the guard test still tolerates it in `http.py` / `server.py`).
14
+ 3. **Pluggable parts = interface + factory.** `factory.register(kind, name, probe=, load=, priority=)`;
15
+ `factory.choose(kind)` takes the override argument, else env `KIKO_<KIND>_IMPL`, else the first
16
+ probe-ok by priority. `factory.report()` feeds `kiko doctor`.
17
+ 4. **Native code only from the OS** (ctypes on system libraries, subprocess on system binaries).
18
+ 5. **No tests inside kikolib**; tests live in the source repository (`tests/kiko/test_kikolib_*.py`, not in the kiko-lite zip).
19
+ 6. **Headers**: every file starts with three lines: `# SPDX-License-Identifier: MIT`,
20
+ `# Copyright (c) 2026 Peter Kokosharov <peter.kokosharov@gmail.com>` and
21
+ `# LLM: <model names, comma separated>`.
22
+
23
+ ## How other projects take kikolib
24
+
25
+ kikolib has one home: this repository (`gateway/kikolib`). Never fork or edit it elsewhere.
26
+
27
+ `pip install kikolib` (PyPI, zero dependencies) is the easy way once a release is published; the
28
+ packaging files `pyproject.toml`, `README-PYPI.md` and `LICENSE` live in this folder. Publishing steps:
29
+ [`docs/PUBLISHING-KIKOLIB.md`](../../docs/PUBLISHING-KIKOLIB.md). Copying the folder still works:
30
+
31
+ 1. Copy the whole `kikolib/` folder, unmodified, from the release tag `kikolib-v0.3.1` (version = `kikolib.__version__`).
32
+ 2. Keep its `SHA256SUMS` in the copy (sha256 of every file, LF endings, sorted; `.gitattributes` forces `eol=lf`).
33
+ Add `<dir>/kikolib/** text eol=lf` to the consumer's own `.gitattributes`, otherwise Windows `autocrlf`
34
+ checkouts change the bytes and the hash check fails.
35
+ 3. Add a test in the consumer that runs the check: `python gateway/tools/kikolib_manifest.py check <copy>/kikolib`
36
+ (copy that script too, it is stdlib only), and assert `kikolib.__version__` equals the pinned version.
37
+ 4. Never edit the copy. To change anything: fix it here, bump the version, add a `CHANGES.md` entry, run
38
+ `python gateway/tools/kikolib_manifest.py write`, release a new tag, re-copy.
39
+
40
+ The test `gateway/tests/kiko/test_kikolib_manifest.py` keeps the manifest from going stale.
41
+
42
+ ### Choosing the HTTP backend (consumers)
43
+
44
+ `http.client()` takes no argument; it calls `factory.choose("http")`. On Windows 10/11 the `winhttp`
45
+ backend (priority 5) beats `stdlib` (priority 10). To pin the stdlib backend either:
46
+
47
+ - set the environment variable before the first `client()` call: `KIKO_HTTP_IMPL=stdlib`, or
48
+ - in code: `factory.choose("http", override="stdlib")` once at start-up (the choice is cached; `client()` then returns it).
49
+
50
+ `KIKO_CA_BUNDLE` set also makes winhttp unavailable (stdlib is used). The default is unchanged.
51
+
52
+ ## Modules
53
+
54
+ | Module | Purpose | Status |
55
+ |---|---|---|
56
+ | `factory.py` | thread-safe implementation registry and chooser | done |
57
+ | `keystore.py` | API keys: env var first, then OS store (wcm, keychain, secret-tool, kwallet, dcop) | done (dcop verified on live TDE/Q4OS by the owner, 2026-11) |
58
+ | `posix.py` | signals, RSS, sd_notify, watchdog, chmod 0o600, atomic private write | done |
59
+ | `config.py` | the one source of paths, ports (base_port) and typed settings (one table); `kiko.toml` via tomllib, read on demand, never at import | done |
60
+ | `tomlwrite.py` | TOML writer: update / insert / remove a key, keeps comments, atomic, refuses what it cannot represent | done |
61
+ | `logs.py` | `[logs] file` handler and the `[logs] retention_days` pruner | done |
62
+ | `dotenv.py` | `.env` reader | done |
63
+ | `tokens.py` | fallback token estimate (not a tokenizer) | done |
64
+ | `http.py` | HTTP client on `http.client` + `ssl`: keep-alive pool, streamed SSE lines, proxy CONNECT, OS trust store | done |
65
+ | `retry.py` | retry policy: exponential backoff + jitter, `Retry-After` within a soft budget, `on_wait` slices for SSE pings | done |
66
+ | `winhttp.py` | HTTP backend "winhttp" (factory kind `http`, priority 5): WinHTTP via ctypes on Windows 10/11, Windows proxy / PAC / SChannel; stdlib stays the fallback (also when `KIKO_CA_BUNDLE` is set) | done |
67
+ | `server.py` | threaded HTTP server, router, `serve()` (signals, systemd, RSS limit, drain) | done |
68
+ | `sse.py` | SSE encode / ping / parser | done |
69
+
70
+ Known limits of `http.Response.abort()` (wakes a reader blocked on a silent upstream from another thread):
71
+ it is a no-op once the response is finished or closed; on Linux `shutdown()` wakes the read; on Windows a
72
+ plain socket is also handle-closed, but a TLS socket is only shut down (closing the handle under a thread in
73
+ `SSL_read` risks a handle-reuse race), so there the worker may live until the read timeout; a worker still
74
+ blocked in `getresponse()` (no response head yet) cannot be aborted and ends at the timeout. The caller's
75
+ own thread is never blocked by any of these. No TLS abort test exists (no stdlib way to make a test cert).
76
+
77
+ Size limits: only `iter_lines` is capped (`MAX_LINE`, 16 MiB). Non-streaming response bodies (`http.py`,
78
+ `winhttp.py`) and `sse.Parser` data lines are not size-capped; kikolib is meant for trusted upstreams.
79
+
80
+ `server.App.browser_guard` is off by default. A consumer serving HTTP must turn it on (kiko does, in
81
+ `kiko_lite/app.py`).
82
+
83
+ No config file long term: settings live in SQLite. `crypto.py` and `jsonschema_lite.py` were removed.
@@ -0,0 +1,20 @@
1
+ fd0395f747542ee09ab209c93f658ce97d5adc1af616cde5d5729de89d0db211 CHANGES.md
2
+ 1d6c6108abaa149fb4e1025a71ba728251dd829152552501440b92d4b6b01f45 LICENSE
3
+ b1e645d1cc55579d57599fa56927c9cbd47a1a5c82904a4a303ea69f02c13d61 README-PYPI.md
4
+ 8423be4248b1e49aa010a357e6930d9fe08f4a2e26363566d3f4d06bc9b29f76 README.md
5
+ e9b40952a56af2defcb27b70be5fc07e94daa95ef9a2ff1dcf42e3806d77249f __init__.py
6
+ 831bed2d59ff497e03d61eb32cca5a3bc21df3c9f6f8961b33b28838f1ac4955 config.py
7
+ 0f347c436ef9a0bc5deb7bb8b77d4295fec1e2ce7ebb4440e4360252c5b125a5 dotenv.py
8
+ 97a2016ba4a6261e9a1c63c2151c6e9f6873bfde7623be6e4beb0952a32270e6 factory.py
9
+ 5c1381ac3eb7f32a2c477fa9241b632626aed616e7b8309187534471760c1944 http.py
10
+ 234cad0ecdb1602fda852695f1e49641c445f0b11b569254da6a932ddd18ba6f keystore.py
11
+ 2e8fcd52c873bb5380ffb7b0e7a7a659a80a45ee9920545ff486fa0198fb4dde logs.py
12
+ fba85f3c6d658ea5086be9962099143f2a95c12457d18191eca25f42f8e8d2fb posix.py
13
+ 72e408431c6d66be9fbb7ed41606360ab974d1760dee9c98551dc81d511a87e7 pyproject.toml
14
+ b7f87de961e7547403e858c602a5682d7d1a4adad796d4b999e9a579ac0b8210 retry.py
15
+ cb5921aaf6104ce2cad5b1496a8684890dd05feb88b4c4c6bcfc6dcce1d5059e server.py
16
+ 4b9b34ad7f38cae8d6e0fc9e8f8d814d6d70368282af4aa47d0a768cd23f21c5 sse.py
17
+ b78f52770d1b51954b06cc9ad78d1778eaf6b656b663be00f053c99f3fad3184 tokens.py
18
+ f541a43be0e65e3f68acf9aa4b1113c20180e528727ad3b1eb631715d0e81acc tomlwrite.py
19
+ 6775e72f66f31bd17a6d5f77767ae72651207aa59e35b5bdb87eb6d78eb95a19 websocket.py
20
+ 7d4d68262adb26b4143baf5e6312aaecd23e012ac8d8be3ca3c88fd5ecdaeaea winhttp.py
@@ -0,0 +1,34 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2026 Peter Kokosharov <peter.kokosharov@gmail.com>
3
+ # LLM: Anthropic Opus, claude-opus-5-5
4
+ """kikolib - small library for kiko-lite: threads (no asyncio), standard library only.
5
+
6
+ Rule: modules here import only the Python standard library and other kikolib
7
+ modules. OS facilities are reached through ctypes or subprocess. Each pluggable
8
+ part has an interface plus a factory (see factory.py) that picks an implementation.
9
+ http.py is a stdlib http backend; server.py (threaded server) and sse.py are done. See kikolib/README.md.
10
+ """
11
+
12
+ import sys
13
+
14
+ if sys.version_info < (3, 11):
15
+ raise RuntimeError("kikolib needs Python 3.11 or newer")
16
+
17
+ __all__ = [
18
+ "config",
19
+ "dotenv",
20
+ "factory",
21
+ "http",
22
+ "keystore",
23
+ "logs",
24
+ "posix",
25
+ "retry",
26
+ "server",
27
+ "sse",
28
+ "tokens",
29
+ "tomlwrite",
30
+ "websocket",
31
+ "winhttp",
32
+ ]
33
+
34
+ __version__ = "0.3.1"