Skip to main content

SmartX RFID

Python Version Version License

Python library for SmartX RFID integrations: device communication, webhook delivery, database utilities, parsing, and support modules for production flows.

Installation

pip install smartx-rfid

For development:

poetry install

Main Modules

  • smartx_rfid.devices
    • RFID: X714, R700_IOT, R420, ACUPAD
    • Generic: SERIAL, TCP
    • Printers: SatoPrinter, SatoWs4Printer
    • DeviceManager
  • smartx_rfid.webhook
    • WebhookManager
    • WebhookXtrack
  • smartx_rfid.db
    • DatabaseManager
  • smartx_rfid.auth
    • token and password helpers
  • smartx_rfid.api
    • Omie and Xtrack API clients
  • smartx_rfid.utils
    • TagList, AlertsManager, delayed_function, hash, regex helpers

Quick Start (Device Events)

import asyncio
from smartx_rfid.devices import X714


async def handle_tag(device: dict, event_data: dict):
    print(f"[{device.get('name')}] EPC={event_data.get('epc')} RSSI={event_data.get('rssi')}")


async def main():
    reader = X714(name="X714-Reader", start_reading=True)

    def on_event(device: dict, event_type: str, event_data: dict):
        if event_type == "tag":
            asyncio.create_task(handle_tag(device, event_data))

    reader.on_event = on_event
    await reader.connect()

    while True:
        await asyncio.sleep(1)


asyncio.run(main())

Webhook Manager

The webhook API now has two explicit sending methods:

  • post_event: standardized event envelope
  • post: custom payload POST

It is designed for burst traffic and includes:

  • async client reuse (keep-alive)
  • request concurrency limiter
  • retry with exponential backoff for network errors, HTTP 429, and HTTP 5xx
  • safe payload serialization for datetime/date, Decimal, bytes, custom objects, dict/list/tuple/set

Constructor

from smartx_rfid.webhook import WebhookManager

webhook = WebhookManager(
    url="https://api.example.com/webhook",  # base URL
    timeout=5.0,
    max_retries=2,
    max_concurrent_requests=50,
)

post_event (standard payload)

success = await webhook.post_event(
    device={"name": "reader-01", "serial_number": "SN123"},
    event_type="tag_read",
    event_data={"epc": "E200001175000001", "rssi": -45.2},
)

Payload format sent by post_event (a plain string device is converted to {"name": ..., "serial_number": null}):

{
  "device": { "name": "reader-01", "serial_number": "SN123" },
  "event_type": "tag_read",
  "event_data": {
    "epc": "E200001175000001",
    "rssi": -45.2
  }
}

post (custom payload + optional URL override)

from datetime import datetime
from decimal import Decimal

payload = {
    "type": "heartbeat",
    "status": "ok",
    "timestamp": datetime.utcnow(),
    "load": Decimal("0.73"),
}

success = await webhook.post(
    payload=payload,
    headers={"X-Source": "rfid-core"},
    url="https://api.example.com/custom-endpoint",  # optional
)

If url is not provided, WebhookManager uses the base URL configured in the constructor.

High-Throughput Example

import asyncio

webhook = WebhookManager(
    url="https://api.example.com/events",
    max_concurrent_requests=20,
    max_retries=2,
)

events = [{"index": i, "ok": True} for i in range(200)]
results = await asyncio.gather(*(webhook.post(payload=e) for e in events))

print(f"sent={sum(results)} failed={len(results) - sum(results)}")
await webhook.aclose()

Recommended pattern:

async with WebhookManager(url="https://api.example.com/events") as webhook:
    await webhook.post_event("reader-01", "connected", {"status": "ok"})

Migration Note

Previous usage:

await webhook.post("device", "event_type", {"data": 1})

Current usage:

await webhook.post_event("device", "event_type", {"data": 1})

For arbitrary payloads, use:

await webhook.post(payload={"anything": "you need"})

Database Example

from datetime import datetime
from sqlalchemy import Column, DateTime, Float, Integer, String
from sqlalchemy.orm import DeclarativeBase
from smartx_rfid.db import DatabaseManager


class Base(DeclarativeBase):
    pass


class TagModel(Base):
    __tablename__ = "rfid_tags"

    id = Column(Integer, primary_key=True)
    epc = Column(String(64), unique=True, nullable=False)
    rssi = Column(Float)
    created_at = Column(DateTime, default=datetime.utcnow)


db = DatabaseManager("sqlite:///rfid_tags.db")
db.register_models(TagModel)
db.create_tables()

with db.get_session() as session:
    session.add(TagModel(epc="E200001175000001", rssi=-45.2))

Event Callback Contract

All devices share a consistent callback contract:

def on_event(device: dict, event_type: str, event_data: dict):
    # device = {"name": "X714-Reader", "serial_number": "SN123" | None}
    # Common event_type values:
    # connected, disconnected, tag, error
    ...

TagList.add(tag, device=device) and EventDispatcher.add/add_async(device, ...) receive this same dict (a plain string is converted to {"name": <string>, "serial_number": None}). Tags stored in TagList include device (name) and device_serial_number. Dispatch templates can use {name}, {serial_number}, {device} and {device[key]}.

Examples Directory

The examples folder includes:

  • examples/devices/RFID
  • examples/devices/generic
  • examples/devices/printer
  • examples/db
  • examples/api
  • examples/email
  • examples/license
  • examples/smtx_db
  • examples/utils

Run examples with:

python examples/devices/RFID/X714_SERIAL.py
python examples/db/showcase.py

Running Tests

pytest

To run only webhook-related tests:

pytest tests/utils/test_serialization.py -k webhook

Requirements

  • Python 3.11+
  • Works on Linux, macOS, and Windows (depending on device transport and drivers)

License

MIT

Support

Metadata

Release files for smartx-rfid 13.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smartx-rfid 13.1.0
File Size Uploaded Provenance Actions
smartx_rfid-13.1.0.tar.gz 3.2 MB Without provenance Details for smartx_rfid-13.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smartx-rfid 13.1.0
File Interpreter ABI Platform Actions
smartx_rfid-13.1.0-py3-none-any.whl Python 3 none any Details for smartx_rfid-13.1.0-py3-none-any.whl

Total release size: 6.6 MB

Release files / smartx_rfid-13.1.0.tar.gz

Download URL smartx_rfid-13.1.0.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
6c0fdf6e70c8665319cca929e4020f3429b6b635040699a1600cd682ad9d3c16
BLAKE2b-256 checksum
How to use checksums
b2535237f5bd204fb888e77900f6223042bc667a262725a340e5d73813ceb95f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / smartx_rfid-13.1.0-py3-none-any.whl

Download URL smartx_rfid-13.1.0-py3-none-any.whl
Size 3.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
3c541fc452bc9b5327f913b6cd84e5bdd256774d254b0dfb0779104b0439d59a
BLAKE2b-256 checksum
How to use checksums
c4a7b733256e33e07c3f155a5c3d4d1129cfdaead8e34c7f31a3fe4fca8c50c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for smartx-rfid 13.1.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.

Release history Release notifications | RSS feed

This release

13.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page