sirannon-client 0.1.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.
- sirannon_client-0.1.0/.gitignore +127 -0
- sirannon_client-0.1.0/LICENSE +201 -0
- sirannon_client-0.1.0/PKG-INFO +57 -0
- sirannon_client-0.1.0/README.md +26 -0
- sirannon_client-0.1.0/pyproject.toml +80 -0
- sirannon_client-0.1.0/src/sirannon_client/__init__.py +35 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_client.py +136 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_operations/__init__.py +19 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_operations/backups.py +274 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_operations/device_sync.py +174 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_operations/encryption.py +87 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_operations/operations.py +100 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_operations/server.py +144 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_operations/statements.py +241 -0
- sirannon_client-0.1.0/src/sirannon_client/_async_topology.py +189 -0
- sirannon_client-0.1.0/src/sirannon_client/_channels.py +173 -0
- sirannon_client-0.1.0/src/sirannon_client/_client.py +210 -0
- sirannon_client-0.1.0/src/sirannon_client/_contracts.py +35 -0
- sirannon_client-0.1.0/src/sirannon_client/_database.py +382 -0
- sirannon_client-0.1.0/src/sirannon_client/_errors.py +113 -0
- sirannon_client-0.1.0/src/sirannon_client/_events.py +116 -0
- sirannon_client-0.1.0/src/sirannon_client/_exchange.py +34 -0
- sirannon_client-0.1.0/src/sirannon_client/_http.py +290 -0
- sirannon_client-0.1.0/src/sirannon_client/_live.py +104 -0
- sirannon_client-0.1.0/src/sirannon_client/_model.py +35 -0
- sirannon_client-0.1.0/src/sirannon_client/_operations/__init__.py +19 -0
- sirannon_client-0.1.0/src/sirannon_client/_operations/backups.py +274 -0
- sirannon_client-0.1.0/src/sirannon_client/_operations/device_sync.py +174 -0
- sirannon_client-0.1.0/src/sirannon_client/_operations/encryption.py +87 -0
- sirannon_client-0.1.0/src/sirannon_client/_operations/operations.py +100 -0
- sirannon_client-0.1.0/src/sirannon_client/_operations/server.py +144 -0
- sirannon_client-0.1.0/src/sirannon_client/_operations/statements.py +241 -0
- sirannon_client-0.1.0/src/sirannon_client/_options.py +112 -0
- sirannon_client-0.1.0/src/sirannon_client/_pacing.py +63 -0
- sirannon_client-0.1.0/src/sirannon_client/_refs.py +86 -0
- sirannon_client-0.1.0/src/sirannon_client/_router.py +251 -0
- sirannon_client-0.1.0/src/sirannon_client/_routing.py +102 -0
- sirannon_client-0.1.0/src/sirannon_client/_sync_database.py +240 -0
- sirannon_client-0.1.0/src/sirannon_client/_sync_runtime.py +131 -0
- sirannon_client-0.1.0/src/sirannon_client/_tasks.py +18 -0
- sirannon_client-0.1.0/src/sirannon_client/_topology_channel.py +144 -0
- sirannon_client-0.1.0/src/sirannon_client/_topology_streams.py +156 -0
- sirannon_client-0.1.0/src/sirannon_client/_values.py +77 -0
- sirannon_client-0.1.0/src/sirannon_client/_ws.py +345 -0
- sirannon_client-0.1.0/src/sirannon_client/_ws_state.py +186 -0
- sirannon_client-0.1.0/src/sirannon_client/models/__init__.py +1635 -0
- sirannon_client-0.1.0/src/sirannon_client/py.typed +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
logs
|
|
2
|
+
*.log
|
|
3
|
+
npm-debug.log*
|
|
4
|
+
yarn-debug.log*
|
|
5
|
+
yarn-error.log*
|
|
6
|
+
lerna-debug.log*
|
|
7
|
+
|
|
8
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
9
|
+
|
|
10
|
+
pids
|
|
11
|
+
*.pid
|
|
12
|
+
*.seed
|
|
13
|
+
*.pid.lock
|
|
14
|
+
|
|
15
|
+
lib-cov
|
|
16
|
+
|
|
17
|
+
coverage
|
|
18
|
+
*.lcov
|
|
19
|
+
|
|
20
|
+
.nyc_output
|
|
21
|
+
|
|
22
|
+
.grunt
|
|
23
|
+
|
|
24
|
+
bower_components
|
|
25
|
+
|
|
26
|
+
.lock-wscript
|
|
27
|
+
|
|
28
|
+
build/Release
|
|
29
|
+
|
|
30
|
+
node_modules/
|
|
31
|
+
jspm_packages/
|
|
32
|
+
|
|
33
|
+
web_modules/
|
|
34
|
+
|
|
35
|
+
*.tsbuildinfo
|
|
36
|
+
|
|
37
|
+
.npm
|
|
38
|
+
|
|
39
|
+
.eslintcache
|
|
40
|
+
|
|
41
|
+
.stylelintcache
|
|
42
|
+
|
|
43
|
+
.node_repl_history
|
|
44
|
+
|
|
45
|
+
*.tgz
|
|
46
|
+
|
|
47
|
+
.yarn-integrity
|
|
48
|
+
|
|
49
|
+
.env
|
|
50
|
+
.env.*
|
|
51
|
+
!.env.example
|
|
52
|
+
|
|
53
|
+
.cache
|
|
54
|
+
.parcel-cache
|
|
55
|
+
|
|
56
|
+
.next
|
|
57
|
+
out
|
|
58
|
+
|
|
59
|
+
.nuxt
|
|
60
|
+
dist
|
|
61
|
+
.output
|
|
62
|
+
.turbo
|
|
63
|
+
|
|
64
|
+
.cache/
|
|
65
|
+
|
|
66
|
+
.vuepress/dist
|
|
67
|
+
|
|
68
|
+
.temp
|
|
69
|
+
.cache
|
|
70
|
+
|
|
71
|
+
.svelte-kit/
|
|
72
|
+
|
|
73
|
+
**/.vitepress/dist
|
|
74
|
+
|
|
75
|
+
**/.vitepress/cache
|
|
76
|
+
|
|
77
|
+
.docusaurus
|
|
78
|
+
|
|
79
|
+
.serverless/
|
|
80
|
+
|
|
81
|
+
.fusebox/
|
|
82
|
+
|
|
83
|
+
.dynamodb/
|
|
84
|
+
|
|
85
|
+
.firebase/
|
|
86
|
+
|
|
87
|
+
.tern-port
|
|
88
|
+
|
|
89
|
+
.vscode-test
|
|
90
|
+
|
|
91
|
+
.pnpm-store
|
|
92
|
+
|
|
93
|
+
.pnp.*
|
|
94
|
+
.yarn/*
|
|
95
|
+
!.yarn/patches
|
|
96
|
+
!.yarn/plugins
|
|
97
|
+
!.yarn/releases
|
|
98
|
+
!.yarn/sdks
|
|
99
|
+
!.yarn/versions
|
|
100
|
+
|
|
101
|
+
vite.config.js.timestamp-*
|
|
102
|
+
vite.config.ts.timestamp-*
|
|
103
|
+
.vite/
|
|
104
|
+
|
|
105
|
+
__pycache__/
|
|
106
|
+
*.py[cod]
|
|
107
|
+
.venv/
|
|
108
|
+
|
|
109
|
+
.nx/
|
|
110
|
+
|
|
111
|
+
loadtest/results*/
|
|
112
|
+
packages/ts/failover-results.json
|
|
113
|
+
|
|
114
|
+
native/npm/*/*
|
|
115
|
+
!native/npm/*/package.json
|
|
116
|
+
!native/npm/*/README.md
|
|
117
|
+
|
|
118
|
+
native/sqlite/out/
|
|
119
|
+
native/sqlite/npm/*/*
|
|
120
|
+
!native/sqlite/npm/*/package.json
|
|
121
|
+
!native/sqlite/npm/*/README.md
|
|
122
|
+
!native/sqlite/npm/sirannon-sqlite/index.js
|
|
123
|
+
!native/sqlite/npm/sirannon-sqlite/index.d.ts
|
|
124
|
+
|
|
125
|
+
native/vfs-encryption-prototype/*.dylib
|
|
126
|
+
native/vfs-encryption-prototype/*.so
|
|
127
|
+
native/vfs-encryption-prototype/*.dll
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Delali (https://sondelali.com)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sirannon-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for the Sirannon database server, with a typed method for every HTTP route, change subscriptions that resume after a reconnection, live queries, and topology-aware routing.
|
|
5
|
+
Project-URL: Homepage, https://sirannon.sondelali.com
|
|
6
|
+
Project-URL: Documentation, https://github.com/assetcorp/sirannon-db/blob/main/docs/python-client.md
|
|
7
|
+
Project-URL: Repository, https://github.com/assetcorp/sirannon-db
|
|
8
|
+
Project-URL: Issues, https://github.com/assetcorp/sirannon-db/issues
|
|
9
|
+
Author: Delali
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: change data capture,client,database,live queries,sirannon,sqlite
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Requires-Dist: httpx<1,>=0.28
|
|
27
|
+
Requires-Dist: pydantic<3,>=2.11
|
|
28
|
+
Requires-Dist: typing-extensions>=4.12
|
|
29
|
+
Requires-Dist: websockets<18,>=15
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Sirannon Python client
|
|
33
|
+
|
|
34
|
+
`sirannon-client` connects a Python 3.11 or later program to a [Sirannon](https://sirannon.sondelali.com) server over WebSocket or HTTP. `SirannonClient` blocks until the server answers, while `AsyncSirannonClient` has the same methods as coroutines for `asyncio`.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install sirannon-client
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from sirannon_client import SirannonClient
|
|
42
|
+
|
|
43
|
+
with SirannonClient("http://localhost:9876") as client:
|
|
44
|
+
db = client.database("orders")
|
|
45
|
+
db.execute("INSERT INTO orders (id, total) VALUES (?, ?)", [42, 4999])
|
|
46
|
+
rows = db.query("SELECT id, total FROM orders WHERE id = ?", [42])
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The client returns every integer as an `int` and every BLOB as `bytes`, including integers beyond 2^53. It has a typed method for every HTTP route of the server, and it calls registered operations through the references that `sirannon-codegen --python` writes.
|
|
50
|
+
|
|
51
|
+
When a connection drops, a change subscription resumes from the last change that it delivered. While the server keeps the history after that change, the subscription delivers each change once, in order; once the server prunes that history, the client calls `on_reset`. A live query updates its rows as the table changes. `TopologyAwareClient` sends writes to the primary of a replication group and sends reads to the nodes that its `read_preference` selects. The client raises `SirannonError` for every failure, with the server's code unchanged.
|
|
52
|
+
|
|
53
|
+
The [Python client guide](https://github.com/assetcorp/sirannon-db/blob/main/docs/python-client.md) explains each of these.
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
`python3 scripts/tools.py` creates a virtual environment from the hashed `requirements-dev.txt` and starts a tool inside it, such as `python3 scripts/tools.py pytest`. `python3 scripts/tools.py python -m generator` checks that the generated models and route methods match `packages/ts/openapi.json` and `packages/ts/asyncapi.json`, and `--write` rewrites them. The tests start the server from `packages/ts/scripts/client-test-server.mjs`, so build `packages/ts` first.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Sirannon Python client
|
|
2
|
+
|
|
3
|
+
`sirannon-client` connects a Python 3.11 or later program to a [Sirannon](https://sirannon.sondelali.com) server over WebSocket or HTTP. `SirannonClient` blocks until the server answers, while `AsyncSirannonClient` has the same methods as coroutines for `asyncio`.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install sirannon-client
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from sirannon_client import SirannonClient
|
|
11
|
+
|
|
12
|
+
with SirannonClient("http://localhost:9876") as client:
|
|
13
|
+
db = client.database("orders")
|
|
14
|
+
db.execute("INSERT INTO orders (id, total) VALUES (?, ?)", [42, 4999])
|
|
15
|
+
rows = db.query("SELECT id, total FROM orders WHERE id = ?", [42])
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The client returns every integer as an `int` and every BLOB as `bytes`, including integers beyond 2^53. It has a typed method for every HTTP route of the server, and it calls registered operations through the references that `sirannon-codegen --python` writes.
|
|
19
|
+
|
|
20
|
+
When a connection drops, a change subscription resumes from the last change that it delivered. While the server keeps the history after that change, the subscription delivers each change once, in order; once the server prunes that history, the client calls `on_reset`. A live query updates its rows as the table changes. `TopologyAwareClient` sends writes to the primary of a replication group and sends reads to the nodes that its `read_preference` selects. The client raises `SirannonError` for every failure, with the server's code unchanged.
|
|
21
|
+
|
|
22
|
+
The [Python client guide](https://github.com/assetcorp/sirannon-db/blob/main/docs/python-client.md) explains each of these.
|
|
23
|
+
|
|
24
|
+
## Development
|
|
25
|
+
|
|
26
|
+
`python3 scripts/tools.py` creates a virtual environment from the hashed `requirements-dev.txt` and starts a tool inside it, such as `python3 scripts/tools.py pytest`. `python3 scripts/tools.py python -m generator` checks that the generated models and route methods match `packages/ts/openapi.json` and `packages/ts/asyncapi.json`, and `--write` rewrites them. The tests start the server from `packages/ts/scripts/client-test-server.mjs`, so build `packages/ts` first.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sirannon-client"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python client for the Sirannon database server, with a typed method for every HTTP route, change subscriptions that resume after a reconnection, live queries, and topology-aware routing."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Delali" }]
|
|
10
|
+
keywords = ["sirannon", "sqlite", "database", "change data capture", "live queries", "client"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Framework :: AsyncIO",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Topic :: Database :: Front-Ends",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.28,<1",
|
|
27
|
+
"pydantic>=2.11,<3",
|
|
28
|
+
"typing-extensions>=4.12",
|
|
29
|
+
"websockets>=15,<18",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://sirannon.sondelali.com"
|
|
34
|
+
Documentation = "https://github.com/assetcorp/sirannon-db/blob/main/docs/python-client.md"
|
|
35
|
+
Repository = "https://github.com/assetcorp/sirannon-db"
|
|
36
|
+
Issues = "https://github.com/assetcorp/sirannon-db/issues"
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["hatchling>=1.27"]
|
|
40
|
+
build-backend = "hatchling.build"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/sirannon_client"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.sdist]
|
|
46
|
+
include = ["src/sirannon_client", "README.md", "LICENSE"]
|
|
47
|
+
|
|
48
|
+
[tool.ruff]
|
|
49
|
+
line-length = 120
|
|
50
|
+
target-version = "py311"
|
|
51
|
+
extend-exclude = [".venv"]
|
|
52
|
+
|
|
53
|
+
[tool.ruff.lint]
|
|
54
|
+
select = ["ASYNC", "B", "E", "F", "I", "PERF", "PIE", "RUF", "S", "SIM", "UP", "W"]
|
|
55
|
+
ignore = ["RUF001", "RUF002", "S101", "S603", "S607"]
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint.isort]
|
|
58
|
+
known-first-party = ["sirannon_client", "generator"]
|
|
59
|
+
|
|
60
|
+
[tool.mypy]
|
|
61
|
+
python_version = "3.11"
|
|
62
|
+
strict = true
|
|
63
|
+
mypy_path = "src"
|
|
64
|
+
files = ["src", "generator", "tests", "scripts"]
|
|
65
|
+
plugins = ["pydantic.mypy"]
|
|
66
|
+
warn_unreachable = true
|
|
67
|
+
|
|
68
|
+
[[tool.mypy.overrides]]
|
|
69
|
+
module = ["sirannon_client._client", "sirannon_client._async_client"]
|
|
70
|
+
disable_error_code = ["override"]
|
|
71
|
+
|
|
72
|
+
[tool.pydantic-mypy]
|
|
73
|
+
init_forbid_extra = false
|
|
74
|
+
init_typed = true
|
|
75
|
+
warn_required_dynamic_aliases = true
|
|
76
|
+
|
|
77
|
+
[tool.pytest.ini_options]
|
|
78
|
+
pythonpath = ["src", "."]
|
|
79
|
+
testpaths = ["tests"]
|
|
80
|
+
addopts = "-p no:cacheprovider"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""The sirannon_client package connects Python code to a Sirannon database server."""
|
|
2
|
+
|
|
3
|
+
from sirannon_client._async_client import AsyncSirannonClient
|
|
4
|
+
from sirannon_client._async_topology import AsyncTopologyAwareClient
|
|
5
|
+
from sirannon_client._client import SirannonClient, TopologyAwareClient
|
|
6
|
+
from sirannon_client._database import AsyncLiveQuery, AsyncRemoteDatabase, AsyncSubscription, AsyncSubscriptionBuilder
|
|
7
|
+
from sirannon_client._errors import ErrorCodes, SirannonError
|
|
8
|
+
from sirannon_client._events import ChangeEvent
|
|
9
|
+
from sirannon_client._live import LiveState, LiveUpdate
|
|
10
|
+
from sirannon_client._refs import BoundRead, BoundWrite, ReadRef, WriteRef
|
|
11
|
+
from sirannon_client._sync_database import LiveQuery, RemoteDatabase, Subscription, SubscriptionBuilder
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"AsyncLiveQuery",
|
|
15
|
+
"AsyncRemoteDatabase",
|
|
16
|
+
"AsyncSirannonClient",
|
|
17
|
+
"AsyncSubscription",
|
|
18
|
+
"AsyncSubscriptionBuilder",
|
|
19
|
+
"AsyncTopologyAwareClient",
|
|
20
|
+
"BoundRead",
|
|
21
|
+
"BoundWrite",
|
|
22
|
+
"ChangeEvent",
|
|
23
|
+
"ErrorCodes",
|
|
24
|
+
"LiveQuery",
|
|
25
|
+
"LiveState",
|
|
26
|
+
"LiveUpdate",
|
|
27
|
+
"ReadRef",
|
|
28
|
+
"RemoteDatabase",
|
|
29
|
+
"SirannonClient",
|
|
30
|
+
"SirannonError",
|
|
31
|
+
"Subscription",
|
|
32
|
+
"SubscriptionBuilder",
|
|
33
|
+
"TopologyAwareClient",
|
|
34
|
+
"WriteRef",
|
|
35
|
+
]
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
4
|
+
from types import TracebackType
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from sirannon_client._async_operations import AsyncOperations
|
|
9
|
+
from sirannon_client._channels import Channel, HttpChannel, WebSocketChannel
|
|
10
|
+
from sirannon_client._database import AsyncRemoteDatabase
|
|
11
|
+
from sirannon_client._errors import closed_error
|
|
12
|
+
from sirannon_client._exchange import path_segment
|
|
13
|
+
from sirannon_client._http import AsyncHttp
|
|
14
|
+
from sirannon_client._options import (
|
|
15
|
+
DEFAULT_MAX_RESPONSE_BYTES,
|
|
16
|
+
DEFAULT_RECONNECT_INTERVAL_MS,
|
|
17
|
+
DEFAULT_REQUEST_TIMEOUT_MS,
|
|
18
|
+
ClientSettings,
|
|
19
|
+
TransportKind,
|
|
20
|
+
build_settings,
|
|
21
|
+
)
|
|
22
|
+
from sirannon_client._ws import AsyncWebSocketTransport
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def open_database(
|
|
26
|
+
settings: ClientSettings, http: AsyncHttp, database_id: str, on_close: Callable[[str], None]
|
|
27
|
+
) -> AsyncRemoteDatabase:
|
|
28
|
+
segment = path_segment(database_id)
|
|
29
|
+
socket: AsyncWebSocketTransport | None = None
|
|
30
|
+
channel: Channel
|
|
31
|
+
if settings.transport == "websocket":
|
|
32
|
+
socket = AsyncWebSocketTransport(f"{settings.websocket_url}/db/{segment}", settings)
|
|
33
|
+
channel = WebSocketChannel(socket)
|
|
34
|
+
else:
|
|
35
|
+
channel = HttpChannel(http, database_id)
|
|
36
|
+
opened_socket = socket
|
|
37
|
+
|
|
38
|
+
async def close() -> None:
|
|
39
|
+
on_close(database_id)
|
|
40
|
+
if opened_socket is not None:
|
|
41
|
+
await opened_socket.aclose()
|
|
42
|
+
|
|
43
|
+
return AsyncRemoteDatabase(database_id, channel, http, socket, close)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class AsyncSirannonClient(AsyncOperations):
|
|
47
|
+
"""Connects to one Sirannon server from asyncio code.
|
|
48
|
+
|
|
49
|
+
The client has one method for each route of the server. Its `database(id)` method returns the handle for
|
|
50
|
+
statements, registered operations, change subscriptions, and live queries. Close the client with `aclose`,
|
|
51
|
+
or use it with `async with`.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
url: str,
|
|
57
|
+
*,
|
|
58
|
+
transport: TransportKind = "websocket",
|
|
59
|
+
headers: Mapping[str, str] | None = None,
|
|
60
|
+
websocket_protocols: str | Sequence[str] | None = None,
|
|
61
|
+
auto_reconnect: bool = True,
|
|
62
|
+
reconnect_interval_ms: int = DEFAULT_RECONNECT_INTERVAL_MS,
|
|
63
|
+
request_timeout_ms: int = DEFAULT_REQUEST_TIMEOUT_MS,
|
|
64
|
+
max_response_bytes: int = DEFAULT_MAX_RESPONSE_BYTES,
|
|
65
|
+
http_client: httpx.AsyncClient | None = None,
|
|
66
|
+
) -> None:
|
|
67
|
+
"""Prepares a client for the server at `url`, without opening a connection before the first call.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
url: The server's base address, such as `https://db.example.com`.
|
|
71
|
+
transport: With `websocket`, the client sends statements over one WebSocket for each database, and
|
|
72
|
+
only this transport supports subscriptions and live queries. With `http`, the client sends each
|
|
73
|
+
statement as an HTTP request.
|
|
74
|
+
headers: The client sends these headers with every HTTP request and WebSocket handshake.
|
|
75
|
+
websocket_protocols: The client offers these subprotocols after `sirannon.v1`, such as a value that
|
|
76
|
+
holds a credential for a server that reads one from the handshake.
|
|
77
|
+
auto_reconnect: When this is true, the client reconnects after a WebSocket drops and restores every
|
|
78
|
+
subscription.
|
|
79
|
+
reconnect_interval_ms: The client waits this long between reconnection tries.
|
|
80
|
+
request_timeout_ms: The client waits this long for each answer, and with 0 it waits without a limit.
|
|
81
|
+
max_response_bytes: The client refuses an answer larger than this, and with 0 it accepts any size.
|
|
82
|
+
http_client: An `httpx.AsyncClient` to send HTTP requests through, which the caller closes.
|
|
83
|
+
"""
|
|
84
|
+
self._settings = build_settings(
|
|
85
|
+
url,
|
|
86
|
+
transport=transport,
|
|
87
|
+
headers=headers,
|
|
88
|
+
websocket_protocols=websocket_protocols,
|
|
89
|
+
auto_reconnect=auto_reconnect,
|
|
90
|
+
reconnect_interval_ms=reconnect_interval_ms,
|
|
91
|
+
request_timeout_ms=request_timeout_ms,
|
|
92
|
+
max_response_bytes=max_response_bytes,
|
|
93
|
+
)
|
|
94
|
+
self._transport = AsyncHttp(self._settings, http_client)
|
|
95
|
+
self._databases: dict[str, AsyncRemoteDatabase] = {}
|
|
96
|
+
self._closed = False
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def settings(self) -> ClientSettings:
|
|
100
|
+
"""The validated settings that this client connects with."""
|
|
101
|
+
return self._settings
|
|
102
|
+
|
|
103
|
+
def database(self, database_id: str) -> AsyncRemoteDatabase:
|
|
104
|
+
"""Returns the handle for one database and keeps it, so a later call with the same id returns that handle."""
|
|
105
|
+
if self._closed:
|
|
106
|
+
raise closed_error()
|
|
107
|
+
existing = self._databases.get(database_id)
|
|
108
|
+
if existing is not None:
|
|
109
|
+
return existing
|
|
110
|
+
opened = open_database(self._settings, self._transport, database_id, self._forget)
|
|
111
|
+
self._databases[database_id] = opened
|
|
112
|
+
return opened
|
|
113
|
+
|
|
114
|
+
def _forget(self, database_id: str) -> None:
|
|
115
|
+
self._databases.pop(database_id, None)
|
|
116
|
+
|
|
117
|
+
async def aclose(self) -> None:
|
|
118
|
+
"""Closes every database handle and connection, so every call in flight fails with `TRANSPORT_ERROR`."""
|
|
119
|
+
if self._closed:
|
|
120
|
+
return
|
|
121
|
+
self._closed = True
|
|
122
|
+
databases, self._databases = list(self._databases.values()), {}
|
|
123
|
+
for database in databases:
|
|
124
|
+
await database.aclose()
|
|
125
|
+
await self._transport.aclose()
|
|
126
|
+
|
|
127
|
+
async def __aenter__(self) -> AsyncSirannonClient:
|
|
128
|
+
return self
|
|
129
|
+
|
|
130
|
+
async def __aexit__(
|
|
131
|
+
self,
|
|
132
|
+
exc_type: type[BaseException] | None,
|
|
133
|
+
exc: BaseException | None,
|
|
134
|
+
traceback: TracebackType | None,
|
|
135
|
+
) -> None:
|
|
136
|
+
await self.aclose()
|