axio-context-sqlite 0.6.1__tar.gz → 0.6.2__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.
@@ -10,3 +10,5 @@ dist/
10
10
  build/
11
11
  _build/
12
12
  .DS_Store
13
+ *.sqlite
14
+ *.db
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: axio-context-sqlite
3
- Version: 0.6.1
3
+ Version: 0.6.2
4
4
  Summary: SQLite-backed context store for Axio
5
5
  Project-URL: Homepage, https://github.com/axio-agent/monorepo
6
6
  Project-URL: Repository, https://github.com/axio-agent/monorepo
@@ -27,6 +27,32 @@ pip install axio-context-sqlite
27
27
 
28
28
  ## Usage
29
29
 
30
+ ### `connect(db_path)`
31
+
32
+ Open (or create) a SQLite database at `db_path` and initialise the schema.
33
+ Returns an `aiosqlite.Connection`. The caller is responsible for closing it.
34
+
35
+ ```python
36
+ async def main():
37
+ conn = await connect("~/.axio/chat.db")
38
+ # ... use the connection ...
39
+ await conn.close()
40
+ ```
41
+
42
+ The helper enables WAL journal mode and a 5-second busy timeout so concurrent
43
+ readers and a single writer can safely share the same database file.
44
+
45
+ ### `SQLiteContextStore(conn, session_id, project=None, db_name="axio_context")`
46
+
47
+ Create a context store bound to one session.
48
+
49
+ | Parameter | Type | Default | Description |
50
+ |-----------|------|---------|-------------|
51
+ | `conn` | `aiosqlite.Connection` | — | Open database connection (from `connect()`) |
52
+ | `session_id` | `str` | — | Unique identifier for this conversation session |
53
+ | `project` | `str \| None` | `str(Path.cwd().resolve())` | Logical project scope used to group and list sessions. Defaults to the current working directory. |
54
+ | `db_name` | `str` | `"axio_context"` | Prefix used for the database table names (`axio_context_messages`, `axio_context_tokens`). |
55
+
30
56
  Open a connection with `connect()`, then create a `SQLiteContextStore` bound to a
31
57
  session. The caller owns the connection and is responsible for closing it.
32
58
 
@@ -56,6 +82,22 @@ asyncio.run(main())
56
82
  conversation history across process restarts. Multiple sessions can coexist in
57
83
  the same database file, isolated by `session_id` and `project`.
58
84
 
85
+ #### Storage and compression
86
+
87
+ Message content is stored as serialized JSON. Payloads larger than 512 bytes
88
+ are automatically compressed with gzip (compresslevel 6) and stored
89
+ base64-encoded with a `gzip:` prefix. Smaller payloads are stored as-is with a
90
+ `plain:` prefix. Decompression happens transparently on read — callers never
91
+ see the encoded form.
92
+
93
+ #### SQLite performance settings
94
+
95
+ Every connection opened by `connect()` is configured with:
96
+
97
+ - `PRAGMA journal_mode=WAL` — enables concurrent readers alongside one writer
98
+ - `PRAGMA busy_timeout=5000` — waits up to 5 seconds before raising a lock error
99
+ - `PRAGMA synchronous=NORMAL` — balances durability and write throughput
100
+
59
101
  ### Agent integration
60
102
 
61
103
  <!--
@@ -112,6 +154,16 @@ async def main() -> None:
112
154
  asyncio.run(main())
113
155
  ```
114
156
 
157
+ ### Token accounting
158
+
159
+ `add_context_tokens(input_tokens, output_tokens)` atomically increments the
160
+ stored token counts for the current session and project using a SQL UPSERT
161
+ (`INSERT ... ON CONFLICT DO UPDATE SET ... = ... + excluded....`). This is safe
162
+ to call concurrently from multiple coroutines without an application-level lock.
163
+
164
+ `set_context_tokens()` replaces the counts unconditionally, and
165
+ `get_context_tokens()` returns a `(input_tokens, output_tokens)` tuple.
166
+
115
167
  ### Forking
116
168
 
117
169
  `fork()` copies the current session's messages into a new session — useful for
@@ -14,6 +14,32 @@ pip install axio-context-sqlite
14
14
 
15
15
  ## Usage
16
16
 
17
+ ### `connect(db_path)`
18
+
19
+ Open (or create) a SQLite database at `db_path` and initialise the schema.
20
+ Returns an `aiosqlite.Connection`. The caller is responsible for closing it.
21
+
22
+ ```python
23
+ async def main():
24
+ conn = await connect("~/.axio/chat.db")
25
+ # ... use the connection ...
26
+ await conn.close()
27
+ ```
28
+
29
+ The helper enables WAL journal mode and a 5-second busy timeout so concurrent
30
+ readers and a single writer can safely share the same database file.
31
+
32
+ ### `SQLiteContextStore(conn, session_id, project=None, db_name="axio_context")`
33
+
34
+ Create a context store bound to one session.
35
+
36
+ | Parameter | Type | Default | Description |
37
+ |-----------|------|---------|-------------|
38
+ | `conn` | `aiosqlite.Connection` | — | Open database connection (from `connect()`) |
39
+ | `session_id` | `str` | — | Unique identifier for this conversation session |
40
+ | `project` | `str \| None` | `str(Path.cwd().resolve())` | Logical project scope used to group and list sessions. Defaults to the current working directory. |
41
+ | `db_name` | `str` | `"axio_context"` | Prefix used for the database table names (`axio_context_messages`, `axio_context_tokens`). |
42
+
17
43
  Open a connection with `connect()`, then create a `SQLiteContextStore` bound to a
18
44
  session. The caller owns the connection and is responsible for closing it.
19
45
 
@@ -43,6 +69,22 @@ asyncio.run(main())
43
69
  conversation history across process restarts. Multiple sessions can coexist in
44
70
  the same database file, isolated by `session_id` and `project`.
45
71
 
72
+ #### Storage and compression
73
+
74
+ Message content is stored as serialized JSON. Payloads larger than 512 bytes
75
+ are automatically compressed with gzip (compresslevel 6) and stored
76
+ base64-encoded with a `gzip:` prefix. Smaller payloads are stored as-is with a
77
+ `plain:` prefix. Decompression happens transparently on read — callers never
78
+ see the encoded form.
79
+
80
+ #### SQLite performance settings
81
+
82
+ Every connection opened by `connect()` is configured with:
83
+
84
+ - `PRAGMA journal_mode=WAL` — enables concurrent readers alongside one writer
85
+ - `PRAGMA busy_timeout=5000` — waits up to 5 seconds before raising a lock error
86
+ - `PRAGMA synchronous=NORMAL` — balances durability and write throughput
87
+
46
88
  ### Agent integration
47
89
 
48
90
  <!--
@@ -99,6 +141,16 @@ async def main() -> None:
99
141
  asyncio.run(main())
100
142
  ```
101
143
 
144
+ ### Token accounting
145
+
146
+ `add_context_tokens(input_tokens, output_tokens)` atomically increments the
147
+ stored token counts for the current session and project using a SQL UPSERT
148
+ (`INSERT ... ON CONFLICT DO UPDATE SET ... = ... + excluded....`). This is safe
149
+ to call concurrently from multiple coroutines without an application-level lock.
150
+
151
+ `set_context_tokens()` replaces the counts unconditionally, and
152
+ `get_context_tokens()` returns a `(input_tokens, output_tokens)` tuple.
153
+
102
154
  ### Forking
103
155
 
104
156
  `fork()` copies the current session's messages into a new session — useful for
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "axio-context-sqlite"
3
- version = "0.6.1"
3
+ version = "0.6.2"
4
4
  description = "SQLite-backed context store for Axio"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"