Files
quicproquo/sdks/python/examples/ffi_demo.py
Christian Nennemann 2e081ead8e chore: rename quicproquo → quicprochat in docs, Docker, CI, and packaging
Rename all project references from quicproquo/qpq to quicprochat/qpc
across documentation, Docker configuration, CI workflows, packaging
scripts, operational configs, and build tooling.

- Docker: crate paths, binary names, user/group, data dirs, env vars
- CI: workflow crate references, binary names, artifact names
- Docs: all markdown files under docs/, SDK READMEs, book.toml
- Packaging: OpenWrt Makefile, init script, UCI config (file renames)
- Scripts: justfile, dev-shell, screenshot, cross-compile, ai_team
- Operations: Prometheus config, alert rules, Grafana dashboard
- Config: .env.example (QPQ_* → QPC_*), CODEOWNERS paths
- Top-level: README, CONTRIBUTING, ROADMAP, CLAUDE.md
2026-03-21 19:14:06 +01:00

61 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Example: synchronous messaging using the Rust FFI backend.
Requires libquicprochat_ffi to be built:
cargo build --release -p quicprochat-ffi
Set QPQ_LIB_PATH if the library is not in the default search path.
Usage:
python ffi_demo.py --server 127.0.0.1:5001 \
--ca-cert ca.pem --user alice --pass secret
"""
from __future__ import annotations
import argparse
from quicprochat import QpqClient, ConnectOptions
def main() -> None:
parser = argparse.ArgumentParser(description="qpq FFI demo")
parser.add_argument("--server", default="127.0.0.1:5001")
parser.add_argument("--ca-cert", default="ca.pem")
parser.add_argument("--server-name", default="")
parser.add_argument("--user", required=True)
parser.add_argument("--pass", dest="password", required=True)
parser.add_argument("--recipient", required=True, help="recipient username")
parser.add_argument("--message", default="hello from Python SDK!")
args = parser.parse_args()
opts = ConnectOptions(
addr=args.server,
ca_cert_path=args.ca_cert,
server_name=args.server_name,
)
client = QpqClient.connect_ffi(opts)
try:
print(f"Connected to {args.server}")
client.ffi_login(args.user, args.password)
print(f"Logged in as {args.user}")
client.ffi_send(args.recipient, args.message.encode("utf-8"))
print(f"Sent message to {args.recipient}")
print("Waiting for messages (5s)...")
messages = client.ffi_receive(timeout_ms=5000)
for msg in messages:
print(f" received: {msg}")
finally:
client.close_sync()
print("Disconnected.")
if __name__ == "__main__":
main()