Swarmauri Tool · QR Code Generator
A Swarmauri tool that converts text payloads into QR codes and returns the image data as a Base64 string. Plug it into conversational agents, marketing workflows, or automation scripts that need scannable hand-offs (URLs, Wi-Fi credentials, one-time tokens, etc.).
- Backed by
qrcode/Pillow to produce standards-compliant QR codes. - Outputs Base64 so responses can be embedded directly in JSON, HTML, or rich chat messages.
- Exposed through the standard Swarmauri tool interface for drop-in registration alongside other capabilities.
Requirements
- Python 3.10 – 3.13.
qrcode(installs with its Pillow dependency) and Swarmauri base packages (swarmauri_base,swarmauri_standard,pydantic).- Optional: downstream consumers often decode the Base64 string using Pillow or write it to disk; ensure those environments can handle binary data.
Installation
Choose the tooling that matches your project; each command resolves transitive dependencies.
pip
pip install swarmauri_tool_qrcodegenerator
Poetry
poetry add swarmauri_tool_qrcodegenerator
uv
# Add to the current project and update uv.lock
uv add swarmauri_tool_qrcodegenerator
# or install into the active environment without editing pyproject.toml
uv pip install swarmauri_tool_qrcodegenerator
Tip: Pillow requires native image libraries on some Linux distributions (e.g.,
libjpeg,zlib). Install OS packages before running the commands above in minimal containers.
Quick Start
import base64
from swarmauri_tool_qrcodegenerator import QrCodeGeneratorTool
qr_tool = QrCodeGeneratorTool()
result = qr_tool("https://docs.swarmauri.ai")
image_b64 = result["image_b64"]
with open("docs-qrcode.png", "wb") as f:
f.write(base64.b64decode(image_b64))
The output image uses the tool's default QR code settings (version=1, low error correction, black modules on white background). Adjust presentation after decoding if you need different colors or scaling.
Usage Scenarios
Embed QR Codes in Agent Responses
from swarmauri_core.agent.Agent import Agent
from swarmauri_core.messages.HumanMessage import HumanMessage
from swarmauri_standard.tools.registry import ToolRegistry
from swarmauri_tool_qrcodegenerator import QrCodeGeneratorTool
registry = ToolRegistry()
registry.register(QrCodeGeneratorTool())
agent = Agent(tool_registry=registry)
message = HumanMessage(content="Create a QR code for https://status.mycompany.com")
response = agent.run(message)
print(response)
Agents can attach the Base64 image to chat payloads so end users scan the code without additional steps.
Publish Dynamic Event Badges
import base64
from pathlib import Path
from swarmauri_tool_qrcodegenerator import QrCodeGeneratorTool
qr_tool = QrCodeGeneratorTool()
attendees = {
"alice": "ticket:EVT-001-A1B2",
"bob": "ticket:EVT-002-B3C4",
}
badges_dir = Path("badges")
badges_dir.mkdir(exist_ok=True)
for name, token in attendees.items():
b64_img = qr_tool(token)["image_b64"]
(badges_dir / f"{name}.png").write_bytes(base64.b64decode(b64_img))
Generate per-attendee QR codes that scanners can translate into ticket tokens at check-in.
Serve Codes Over HTTP
import base64
from fastapi import FastAPI, Response
from swarmauri_tool_qrcodegenerator import QrCodeGeneratorTool
app = FastAPI()
qr_tool = QrCodeGeneratorTool()
@app.get("/qr")
def qr_endpoint(data: str):
result = qr_tool(data)
png_bytes = base64.b64decode(result["image_b64"])
return Response(content=png_bytes, media_type="image/png")
Expose an API that transforms arbitrary data into QR codes your front-end can display.
Troubleshooting
- Blank or unreadable codes – Confirm the Base64 string is decoded to a PNG (
base64.b64decode(...)). Avoid writing the raw Base64 text directly to file. - Binary dependency errors (Pillow) – Install platform-specific libraries (
apt-get install libjpeg-dev zlib1g-dev, etc.) before installing the package, especially in slim containers. - Large payloads – Version 1 QR codes have size constraints (~17 alphanumeric characters). Fork the tool or extend it to allow larger versions if you need to encode lengthy data.
License
swarmauri_tool_qrcodegenerator is released under the Apache 2.0 License. See LICENSE for details.
Metadata
Release files for swarmauri_tool_qrcodegenerator 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_tool_qrcodegenerator-0.10.0.tar.gz | 8.4 kB | Without provenance | Details for swarmauri_tool_qrcodegenerator-0.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_tool_qrcodegenerator-0.10.0-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_tool_qrcodegenerator-0.10.0-py3-none-any.whl |
Total release size: 18.0 kB
Release files / swarmauri_tool_qrcodegenerator-0.10.0.tar.gz
| Download URL | swarmauri_tool_qrcodegenerator-0.10.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e2ae6e25e5e5d11369be6312fb1e4c80ca2ca6511b6b29d005851fb1645b58c
|
|
BLAKE2b-256 checksum How to use checksums |
8c6811dc14005664969f085c29eca10097d1de66e740c05eb4413b34894ed670
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_tool_qrcodegenerator-0.10.0-py3-none-any.whl
| Download URL | swarmauri_tool_qrcodegenerator-0.10.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c03c119f8e696fccbdabca5ab770e754b5a3517294b6ffe0e84934d21655408a
|
|
BLAKE2b-256 checksum How to use checksums |
b77f2cde8465ee20966da6b104fa6885f724a214c9b7335935575aba1367b76c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swarmauri_tool_qrcodegenerator 0.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.