mantisbase 0.1.0__cp313-cp313-win_amd64.whl
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.
- mantisbase-0.1.0.data/platlib/libgcc_s_seh-1-f624cec5b9fb488a28f2f75d1732b4c4.dll +0 -0
- mantisbase-0.1.0.data/platlib/libmantisbase-e050b3dd350633bc9c9f9af979cc2d1b.dll +0 -0
- mantisbase-0.1.0.data/platlib/libstdc++-6-c153bb15d894d855ad6997d725aecfc6.dll +0 -0
- mantisbase-0.1.0.data/platlib/libwinpthread-1-55774e39fda420143ea05738f4fc22a3.dll +0 -0
- mantisbase-0.1.0.dist-info/DELVEWHEEL +2 -0
- mantisbase-0.1.0.dist-info/METADATA +121 -0
- mantisbase-0.1.0.dist-info/RECORD +9 -0
- mantisbase-0.1.0.dist-info/WHEEL +5 -0
- mantisbase.cp313-win_amd64.pyd +0 -0
|
Binary file
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mantisbase
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python bindings for mantisbase – Flask-style HTTP server backed by a C++ engine
|
|
5
|
+
Author: Allan Koech
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: C++
|
|
10
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# mantisbase (Python)
|
|
15
|
+
|
|
16
|
+
Python bindings for [mantisbase](https://github.com/allankoechke/mantisbase), a
|
|
17
|
+
C++20 single-binary backend-as-a-service. Import it like Flask and drive the
|
|
18
|
+
whole server from Python.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install mantisbase
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import mantisbase
|
|
26
|
+
|
|
27
|
+
app = mantisbase.App(port=8080, data_dir="./data")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@app.router.get("/hello/{name}")
|
|
31
|
+
def hello(req, res):
|
|
32
|
+
res.json(200, {"message": f"Hello, {req.path_param('name')}!"})
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.router.post("/items")
|
|
36
|
+
def create_item(req, res):
|
|
37
|
+
body = req.json()
|
|
38
|
+
rows = app.db.query("INSERT INTO items (name) VALUES (:name) RETURNING *",
|
|
39
|
+
{"name": body["name"]})
|
|
40
|
+
res.json(201, rows[0])
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
app.start() # blocks until stop() is called
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
### `App(**config)`
|
|
49
|
+
|
|
50
|
+
Keyword arguments mirror the CLI flags: `port`, `host`, `data_dir`, `db_type`,
|
|
51
|
+
`db_url`, `public_dir`, `scripts_dir`, `migrations_dir`, `pool_size`, `dev`,
|
|
52
|
+
`skip_admin_setup`. `secret_key` sets the `MB_JWT_SECRET` environment variable.
|
|
53
|
+
|
|
54
|
+
- `start(blocking=True)` — run the HTTP server. Pass `blocking=False` to run it
|
|
55
|
+
on a background thread.
|
|
56
|
+
- `stop()` — shut the server down.
|
|
57
|
+
- `router` / `db` — the `Router` and `Database` instances.
|
|
58
|
+
|
|
59
|
+
### `Router`
|
|
60
|
+
|
|
61
|
+
`get(path, handler=None)`, `post(...)`, `patch(...)`, `delete(...)`. Called with
|
|
62
|
+
only a path they return a decorator, so both styles work:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
app.router.get("/a", handler)
|
|
66
|
+
|
|
67
|
+
@app.router.get("/b")
|
|
68
|
+
def handler_b(req, res): ...
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `MantisRequest`
|
|
72
|
+
|
|
73
|
+
`path_param(name)`, `query_param(name)`, `header(name)`, `json()`, `body()`,
|
|
74
|
+
and the read-only properties `method`, `path`, `remote_addr`.
|
|
75
|
+
|
|
76
|
+
### `MantisResponse`
|
|
77
|
+
|
|
78
|
+
`json(status, data)`, `html(status, body)`, `text(status, body)`,
|
|
79
|
+
`send(status, data, content_type)`, `redirect(url, status=302)`,
|
|
80
|
+
`set_header(name, value)`.
|
|
81
|
+
|
|
82
|
+
### `Database`
|
|
83
|
+
|
|
84
|
+
`query(sql, *params)` where each param is a dict of named binds. Returns a list
|
|
85
|
+
of dicts keyed by column name. The GIL is released for the duration of the
|
|
86
|
+
query.
|
|
87
|
+
|
|
88
|
+
## Threading
|
|
89
|
+
|
|
90
|
+
Route handlers are invoked from mantisbase's C++ worker threads, and the GIL is
|
|
91
|
+
acquired before each call. Python handlers therefore serialise against each
|
|
92
|
+
other — the same model as Flask's default threaded server.
|
|
93
|
+
|
|
94
|
+
## Building from source
|
|
95
|
+
|
|
96
|
+
The bindings link the mantisbase shared library, so build and install it first
|
|
97
|
+
(`install` only runs on `cmake --install` — a plain build is not enough):
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cmake -B build -DMB_BUILD_SHARED_LIB=ON
|
|
101
|
+
cmake --build build
|
|
102
|
+
cmake --install build --prefix ./install
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Then point the standalone bindings build at that prefix:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install -e bindings/python \
|
|
109
|
+
--config-settings=cmake.define.CMAKE_PREFIX_PATH=$PWD/install
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Requires CMake >= 3.22, a C++20 compiler, and `nanobind`/`scikit-build-core`
|
|
113
|
+
(fetched automatically via pip build isolation). At runtime the loader must
|
|
114
|
+
find `libmantisbase.so`, e.g. `export LD_LIBRARY_PATH=$PWD/install/lib`.
|
|
115
|
+
|
|
116
|
+
To produce a distributable wheel instead, see `.github/workflows/bindings-python.yml`
|
|
117
|
+
(engine install → `pip wheel` → `auditwheel`/`delocate`/`delvewheel` repair).
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mantisbase.cp313-win_amd64.pyd,sha256=4zQqaEN_7CPj0_AVMfrFwvO22x2jqhKQg2mMJ8OHBME,407040
|
|
2
|
+
mantisbase-0.1.0.data/platlib/libgcc_s_seh-1-f624cec5b9fb488a28f2f75d1732b4c4.dll,sha256=NQTe4lcGcjIvprGmify3CYjui1dbtBVGa81mAB_Wr4I,140800
|
|
3
|
+
mantisbase-0.1.0.data/platlib/libmantisbase-e050b3dd350633bc9c9f9af979cc2d1b.dll,sha256=sqmbyk0jIBKe36m_Z1dbL2cUbhv6BBIXNNt10p0MKdk,15600291
|
|
4
|
+
mantisbase-0.1.0.data/platlib/libstdc++-6-c153bb15d894d855ad6997d725aecfc6.dll,sha256=Vsv4Gn1Fsu8O-qjQHvHEPb5wb81_XsbTDwVsacpGuaQ,2320384
|
|
5
|
+
mantisbase-0.1.0.data/platlib/libwinpthread-1-55774e39fda420143ea05738f4fc22a3.dll,sha256=VXdOOf2kIBQ-oFc49PwioxQuNdPKZe0cgc6ibRu2cK8,57344
|
|
6
|
+
mantisbase-0.1.0.dist-info/DELVEWHEEL,sha256=FipuWkIu84muNNQzNJwangrKWCnvuJ5GYZkz7SY5q-E,194
|
|
7
|
+
mantisbase-0.1.0.dist-info/METADATA,sha256=f3sfRsHd94-9cfrBSwxcXf_BIjrjR6qaW-q2TM2CqS0,3526
|
|
8
|
+
mantisbase-0.1.0.dist-info/RECORD,,
|
|
9
|
+
mantisbase-0.1.0.dist-info/WHEEL,sha256=bzccfTXe5NE7eB86OiS4hIwvwnRsRQgKw2c3BU4To6A,105
|
|
Binary file
|