Skip to main content

SMFLOG

smflog is a high-performance logging library for Python rewritten using Rust and PyO3. Serves as a drop-in extension for print() Python defaults, smflog offers much lower overhead, massive log throughput handling, and separation of log execution between output terminals and persistent SQLite storage.


Key Features & Architecture

Zero-Lag Terminal I/O (smf.printf): Replaces Python's built-in I/O mechanism with Rust FFI bindings optimized for executing large logs without triggering I/O bottlenecks.

Silent SQLite Storage (smf.printd): Isolates debugging logs and error tracebacks directly to a structured SQLite database in the OS /tmp directory without filling up the terminal stdout buffer.

Native Type Ingestion: The FFI layer handles Python data type conversion to Rust strings directly (PyBytes, NoneType, and custom classes via slots __str__).

Python Print Compatible: Supporting conventional arguments such as sep, end, file, And flush.


Technical Performance Highlights

  1. Overhead & Speed: Reduces I/O interrupt overhead on large log executions by moving the text formatting and writing process to the native Rust runtime. Almost completely Zero-Copy.
  2. Crash & Traceback Capture: smf.printd automatically extracts stack traces and variable metadata when catching exceptions, saving them to a structured SQLite table.
  3. Custom design: Built on the basis of modern industrial standards in sensitive environments such as Cloud Data Center (Microservices/Serverless).

Installation

# Pip install via wheel binary (Rust Toolchain required if building from source)
pip install smflog

Usage & API Reference

  1. High-Speed Terminal Output (smf.printf)
    Using an interface identical to print(), but executed in the Rust FFI layer:
import smf

# Custom separators & terminators
smf.printf("A", "B", "C", sep=" | ", end="\n---\n")

# Unpacking payload besar tanpa I/O lag
large_payload = [f"Data_{i}" for i in range(100_000)]
smf.printf(*large_payload, sep=", ")

# Stream redirection ke file object
with open("system.log", "a") as f:
    smf.printf("System status: OK", file=f, flush=True)
  1. Rust FFI Type Handling
    smflog handle Python data type conversions efficiently at the Rust level:
class CustomObject:
    def __str__(self):
        return "<CustomObject String Representation>"

# Handles PyBytes natively (escaped)
bytes = b"Hello\nWorld\x00"
smf.printf("Raw Bytes:", bytes)

# Handles NoneType & Custom Objects via __str__ slot
smf.printf("None Type:", None)
smf.printf("Custom Class:", CustomObject())
  1. Isolated SQLite Debug Logging (smf.printd)
    Save debug state and traceback to SQLite in OS temporary directory (/tmp):
try:
    result = 10 / 0
except Exception as e:
    # Automatically saved in SQLite without polluting the terminal stdout
    smf.printd("Division failed", e, level="ERROR")

Technical Architecture & PyO3 Integration

smflog designed as a high-performance C-Extension that bridges Python Global Interpreter Lock (GIL) with Rust Native Concurrency/I/O Engine.

  +---------------------------------------------------------------------------+
  |                               Python Layer                                |
  |  smf.printf(*args, sep, end, file, flush)      smf.printd(*args, level)   |
  +-------------------------------------+-------------------------------------+
                                        | PyO3 FFI Boundary
  +-------------------------------------v-------------------------------------+
  |                          Rust Native Engine (smf)                         |
  |                                                                           |
  |         +--------------------+             +--------------------+         |
  |         | Fast Type Resolver |             | Traceback Extractor|         |
  |         | (PyBytes/PyStr)    |             | (PyErr/Exception)  |         |
  |         +---------+----------+             +---------+----------+         |
  |                   |                                  |                    |
  |                   v                                  v                    |
  |         +--------------------+             +--------------------+         |
  |         | Direct OS stdout / |             | SQLite Connection  |         |
  |         | BufWriter Engine   |             | Pool (WAL Mode)    |         |
  |         +---------+----------+             +---------+----------+         |
  +-------------------|----------------------------------|--------------------+
                      v                                  v
               System Terminal                 OS /tmp/smflog/log.db (0o700)
  1. PyO3 Type Ingestion & FFI Conversion
    Crucial points in performance smflog is how Python data types are converted to Rust without excessive memory allocation overhead:
  • PyBytes Ingestion: Caught using obj.downcast::<PyBytes>(). Byte streams are processed directly at the Rust buffer level and non-printable characters are escaped automatically.
  • NoneType Isolation: Evaluated directly with C API preprocessing via obj.is_none(), avoiding Python attribute calls.
  • Custom Object Handling: Call slot __str__ on C-Struct Python via obj.str() only if the object is not a primitive type (string, int, float, bytes, bool).
  1. Lock & Thread Safety Design
  • smf.printf: Minimize reading duration GIL (Global Interpreter Lock). Concatenated string formatting (string concatenation) performed in the Rust thread layer before being executed to standard output.
  • smf.printd: Use SQLite Write-Ahead Logging (WAL) Mode which is stored in the OS's built-in temporary directory (/tmp or %TEMP%). Log writing is done in a thread-safe manner using an isolated connection pool to avoid database locked concerns when logs are sent in parallel/massively.

SQLite Database Schema (DDL)

To ensure that the smf.printd query can execute debugging logs and large-capacity tracebacks without causing performance degradation, the following SQLite database schema is automatically applied during module initialization:

-- Database Location: OS Temporary Directory (e.g., /tmp/smflog/log.db)
-- journal mode = WAL (Write Concurrency)
-- synchronous = NORMAL (Balanced Durability)
-- temp_store = MEMORY (RAM Temp Storage)

CREATE TABLE IF NOT EXISTS system_logs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    timestamp REAL,
    level TEXT,
    label TEXT,
    payload TEXT,
    caller TEXT,
    location TEXT,
    traceback TEXT
);",

SQLite Log Schema (smf.printd)

Log data is stored in the OS temporary database with the following schema:

Field Type Description
timestamp DATETIME Time the log was created (ISO-8601 UTC)
level TEXT Log severity (DEBUG, INFO, ERROR, WARN)
label TEXT Taken from the first string
payload TEXT Argument fusion result string
caller TEXT Error script caller location, line number & function
location TEXT The exact location of the error, line number & function
traceback TEXT Captured Python exception stack trace (If there are)

License

This tool is distributed under the GPL License.

Metadata

Release files for smflog 1.2.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 smflog 1.2.0
File Size Uploaded
smflog-1.2.0.tar.gz 25.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for smflog 1.2.0
File Interpreter ABI Platform
smflog-1.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
smflog-1.2.0-cp39-abi3-manylinux_2_34_x86_64.whl CPython 3.9 abi3 Linux glibc 2.34+ x86-64 Details
smflog-1.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details

Total release size: 3.4 MB

Release files / smflog-1.2.0.tar.gz

Download URL smflog-1.2.0.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5b5bae627193878e6ef4cca6c7ca3439e0c42da9f6bcce5f57ecfc858404f44e
BLAKE2b-256 checksum
How to use checksums
06acd24770e0e2d18ca7142e93a2d1a29bcb136c6a446490056f1bd915923b4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release files / smflog-1.2.0-cp39-abi3-win_amd64.whl

Download URL smflog-1.2.0-cp39-abi3-win_amd64.whl
Size 1.1 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0bf2f0287d4fa14cdaafe27061f057e313ae40f82daa70326405d24dbd92cdfe
BLAKE2b-256 checksum
How to use checksums
8a804387019b22bb8e0757d95bf6569dd502af3f783ce8cfec8192427952dcc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release files / smflog-1.2.0-cp39-abi3-manylinux_2_34_x86_64.whl

Download URL smflog-1.2.0-cp39-abi3-manylinux_2_34_x86_64.whl
Size 1.2 MB
Tags CPython 3.9 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
f3870e59bb6ac9daece3c87d315f566fc578f415dfc4434fef4034b6c73b7108
BLAKE2b-256 checksum
How to use checksums
0b235b4250e3f68c4d07856d50f667998a48ce9ea6e94344001193cb41be259f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release files / smflog-1.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL smflog-1.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
79c562514fb2416baca7bc6b104cba7f3e7e4e193454a3d4c571b415a7ced7eb
BLAKE2b-256 checksum
How to use checksums
b9731453cdd651c5eac6fc39c17f56567837a7de55c666bcf58e3d07dd90d554
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release history Release notifications | RSS feed

1.3.0

4 release files

This release

1.2.0 This release

4 release files

1.1.0

4 release files

1.0.6

4 release files

1.0.5

4 release files

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