Allow others to install as a Python dependency.
This commit is contained in:
54
README.md
54
README.md
@@ -46,9 +46,32 @@ cargo build
|
|||||||
|
|
||||||
## Python Usage
|
## Python Usage
|
||||||
|
|
||||||
This crate also exposes Python bindings behind the Cargo feature `python`.
|
`slingshot-microservice` ships Python bindings built with
|
||||||
The Python callback receives a request ID plus callable `read_file` and
|
[PyO3](https://pyo3.rs) and [maturin](https://www.maturin.rs). Pre-built
|
||||||
`write_file` helpers and should yield tuples of `(result_id, case_variable)`.
|
ABI3 wheels work on Python ≥ 3.8 without requiring Rust locally.
|
||||||
|
|
||||||
|
### Installing
|
||||||
|
|
||||||
|
**From PyPI** (once published):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install slingshot-microservice
|
||||||
|
```
|
||||||
|
|
||||||
|
**From git** (Rust toolchain required):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install git+https://codeberg.org/seanhly/slingshot-microservice
|
||||||
|
```
|
||||||
|
|
||||||
|
**From a local clone** (for development):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install maturin
|
||||||
|
pip install -e .
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
@@ -75,16 +98,31 @@ microservice = Microservice("simple-py-microservice", "sys-map.slingshot.cv", pr
|
|||||||
microservice.start()
|
microservice.start()
|
||||||
```
|
```
|
||||||
|
|
||||||
### Building The Python Extension
|
### Type Annotations
|
||||||
|
|
||||||
Build with:
|
`slingshot_microservice.typing` exports `Protocol`-based types for use in
|
||||||
|
editors and type-checkers:
|
||||||
|
|
||||||
|
| Symbol | Description |
|
||||||
|
|---|---|
|
||||||
|
| `ReadFileFn` | Callable returned by `read_file(key, id)` – behaves like `BinaryIO` |
|
||||||
|
| `WriteFileFn` | Callable returned by `write_file(key, id)` – behaves like `BinaryIO` |
|
||||||
|
| `ProcessFn` | The generator function signature expected by `Microservice` |
|
||||||
|
| `CaseVariable` | `bool \| int \| str` – valid case variable types |
|
||||||
|
|
||||||
|
### Publishing Wheels
|
||||||
|
|
||||||
|
Build and upload to PyPI using maturin:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo build --release --features python
|
pip install maturin
|
||||||
|
maturin publish
|
||||||
```
|
```
|
||||||
|
|
||||||
The generated shared library can then be imported by Python as
|
For CI/cross-compilation (Linux, macOS, Windows), use
|
||||||
`slingshot_microservice`.
|
[maturin-action](https://github.com/PyO3/maturin-action) in GitHub/Codeberg
|
||||||
|
Actions. Because the extension is compiled with ABI3 (`abi3-py38`), a single
|
||||||
|
Linux wheel covers all CPython versions ≥ 3.8.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|||||||
19
pyproject.toml
Normal file
19
pyproject.toml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["maturin>=1.7,<2"]
|
||||||
|
build-backend = "maturin"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "slingshot-microservice"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Opinionated Rust framework for queue-driven microservices"
|
||||||
|
license = { text = "MIT" }
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
|
[tool.maturin]
|
||||||
|
# Build with Python bindings enabled.
|
||||||
|
features = ["python"]
|
||||||
|
# Place the native extension inside the Python package so imports resolve.
|
||||||
|
module-name = "slingshot_microservice._native"
|
||||||
|
# Include the pure-Python package (typing stubs, __init__.py) in the wheel.
|
||||||
|
python-packages = ["slingshot_microservice"]
|
||||||
Reference in New Issue
Block a user