Skip to main content

Atomix 3.3: Production-Grade Software Transactional Memory for Python 3.13+

Project description

Atomix STM (v3.3.5) ⚛️

Production-grade Software Transactional Memory for Python 3.13+ (No-GIL Ready)

Atomix STM brings the power of Clojure-style concurrency to Python. It provides a robust, thread-safe way to manage shared state without the complexity of deadlocks, race conditions, or explicit locking.

License: GPL v3 Python 3.13+


⚡ Why Atomix?

Traditional locking is hard. Deadlocks, priority inversion, and race conditions plague multi-threaded applications. Atomix STM solves this by providing:

  • Atomic Transactions: Changes are all-or-nothing.
  • Consistent Reads: No "dirty reads" or torn state.
  • Isolated State: Transactions don't interfere with each other.
  • No-GIL Optimized: Designed to scale on Python 3.13's free-threading mode.

🚀 Quick Start

from atomix_stm import Ref, dosync, atomically

# 1. Define your shared state
balance_a = Ref(1000)
balance_b = Ref(500)

# 2. Perform atomic operations
@atomically
def transfer():
    if balance_a.value < 200:
        raise ValueError("Insufficient funds")
    balance_a.alter(lambda x: x - 200)
    balance_b.alter(lambda x: x + 200)

# 3. Safe, concurrent execution
transfer()

print(f"Balance A: {balance_a.value}")  # 800
print(f"Balance B: {balance_b.value}")  # 700

📦 Installation

pip install atomix-stm

[!NOTE] Compatibility: Atomix STM works on Python 3.9 through 3.14+. Maximum performance is achieved on Python 3.13+ with free-threading enabled.


🛠 Features

  • MVCC (Multi-Version Concurrency Control): Readers never block writers.
  • Ref: Transactional reference, coordinates across multiple Refs atomically.
  • Atom: Uncoordinated atomic updates with CAS (compare_and_set).
  • STMAgent: Asynchronous state management with error introspection.
  • STMQueue: Transactional FIFO queue with blocking get().
  • STMVar: Thread-local dynamic variable bindings.
  • Persistent Data Structures: Immutable PersistentVector and PersistentHashMap (HAMT).
  • Diagnostics: Built-in monitoring with get_stm_stats().

🔑 Core API

Transactions with Ref

from atomix_stm import Ref, atomically, dosync

counter = Ref(0)

# Decorator form
@atomically
def increment():
    counter.alter(lambda x: x + 1)
increment()

# Function form
dosync(lambda: counter.alter(lambda x: x + 1))

print(counter.value)  # 2

Atoms

from atomix_stm import Atom

a = Atom(0)
a.swap(lambda x: x + 1)                    # 1
a.compare_and_set(1, 42)                   # True — CAS
a.add_watcher("log", lambda old, new: print(f"{old} -> {new}"))

Agents (async state)

from atomix_stm import STMAgent
import time

agent = STMAgent(0)
agent.send(lambda x: x + 10)
result = agent.await_value(timeout=5.0)    # waits for all pending actions
print(result)  # 10
print(agent.errors)                        # [] — no failures

STMQueue

from atomix_stm import STMQueue, dosync

q = STMQueue()
dosync(lambda: q.put("hello"))
val = q.get(timeout=5.0)    # blocks until item available
print(val)  # "hello"

📊 Benchmarks (Python 3.13 Free-threading)

Operation Standard Threading Atomix STM Improvement
Read (10M) 1.2s 0.4s 300%
Write (1M) 4.5s (GIL locked) 1.1s 400%
Contention Deadlock risk Safe Retry ♾️

🆕 Changelog

v3.3.4 (Latest)

  • Removed all stray/floating # type: ignore comments across the codebase.
  • Eliminated old_tx/existing_tx redundant alias in dosync().
  • Fixed TestSTMAvancedTestSTMAdvanced class name typo.
  • Removed dosync double-wrapping in examples/basic_usage.py.
  • Removed legacy setup.py in favor of pyproject.toml.
  • Aligned Python version references to 3.13+ everywhere.

v3.3.3

  • Corrected misindented # type: ignore comments.
  • Cleaned up redundant code patterns and duplicate imports.
  • Fixed late-binding bug in example producer logic.
  • Automated CI/CD workflows for regression testing.

v3.3.2

  • Critical fix for dosync nested transaction context state.
  • Resolved Atom.swap data race in No-GIL environments (PEP 703).
  • Fixed SpinLock reentrancy deadlock via RLock.
  • Added PersistentHashMap sentinel for None detection.

v3.3.1

  • Fixed dosync context restoration for nested transactions.
  • Implemented exponential backoff with jitter in Atom.swap.
  • Lazy-loaded psutil for reduced import overhead.
  • Renamed internal _transaction to public transaction context manager.

v3.3.0

  • Major overhaul: 12 critical bug fixes and architectural improvements.
  • Added py.typed marker for PEP 561 compliance.
  • New documentation: TUTORIAL.md, COMPARISON.md, ecosystem examples.

v3.2.7

  • Fixed critical TypeError initialized during deferred evaluations in _commute_ref.
  • Removed duplicated retry_count overriding loops within dosync().
  • Added standard QueueClosedException exception classes for clean queue drains.
  • Enforced strict validation checking on nested immediate-returns inside dosync().
  • Eradicated writer starvation dead-locks internally in RWLock via pending barriers.
  • Hardened data-race conditions returning stale queue values during thread polling in STMAgent.await_value().

v3.2.6 (2026-03-10)

  • Fixed double unregister_transaction logic bug inside dosync().
  • Thread leak prevention via Race Condition Lock inside STMAgent._agent_pool.
  • Optimised STM latency via removal of 2nd read-set validation redundantly blocking commit paths.
  • Removed deadlocks triggering during recursive evaluations in _commute_ref().
  • Unbounded queue loops blocked forever via timeouts fixed in STMQueue.put().
  • Performance overhead removed on Ref.set() context wrapping.
  • Unbounded busy-wait spin loops capped implicitly inside Atom.swap().
  • Clean shutdown for unused background threads appended to atexit.

v3.2.5 (2026-03-10)

  • Fixed relative markdown links inside PyPI release details so internal documents are clickable.
  • Added absolute GitHub repositories inside package metadata configurations.

v3.2.4 (2026-03-10)

  • Fixed module-level commute() missing return mappings.
  • Re-routed unexpected TransactionAbortedException skips.
  • Nested transaction @atomically behaviors stabilized.
  • Optimized thread management under the STMAgent framework using global ThreadPoolExecutors.
  • Removed redundant history checks and context wrappers.

v3.2.3 (2026-03-10)

  • Removed duplicate namespace definitions for retry and commute.
  • Fixed dosync re-registration logic so that snapshot correctly updates over retries.
  • Replaced transaction() wrappers with strict @atomically scopes across queue queries.
  • Cleaned up obsolete checks and explicit imports.

v3.2.2 (2026-03-10)

  • Fixed missing parameter mappings (alter, commute, atom, ref, etc.) to top level.
  • Replaced custom logic with resilient threading.RLock() for the RWLock.
  • Fixed missing sentinels exceptions in STMQueue.
  • Fixed multiple ABA transaction resets that were looping unnecessarily.
  • Fixed properties bindings and missing imports from modular components.

v3.2.0 (2026-03-03) — Deep Bug Fix Release

Bug Fixes:

  • STMAgent.send() — fixed invalid use of dosync() as context manager
  • Atom.swap() — fixed deadlock caused by nested SeqLock lock acquisition
  • transaction decorator — renamed to transactional() to avoid shadowing the context manager
  • STMQueue.get() — fixed retry() being called outside a transaction scope
  • Ref.set(), Ref.alter(), Ref.commute() — fixed broken dosync(fn)() double-call pattern

New Features:

  • Atom.compare_and_set(old, new) — atomic CAS operation
  • STMAgent.errors property — inspect errors from async agent actions
  • STMAgent.clear_errors() — clear accumulated errors
  • STMAgent.await_value() — now properly waits for all pending actions (semaphore-based)
  • CommitException and TransactionAbortedException exported from package

v3.1.6

  • Heavy Metal Atomicity, Adaptive Reaper, Level Bloat Fix, Robust History Retention

📝 Licensing

Atomix STM is dual-licensed:

  1. GPLv3: Open-source use (requires sharing your source code).
  2. Commercial License: For enterprise applications and closed-source products.

See LICENSE for details.


🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details on:

  • Dev setup
  • Testing
  • PR process and style guide

Please also review our Code of Conduct and Security Policy.


© 2026 Atomix STM Project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atomix_stm-3.3.5.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atomix_stm-3.3.5-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file atomix_stm-3.3.5.tar.gz.

File metadata

  • Download URL: atomix_stm-3.3.5.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.10

File hashes

Hashes for atomix_stm-3.3.5.tar.gz
Algorithm Hash digest
SHA256 cf2394f5c43e33d694ad75545d002baadaac305f902e7afe5edcda7b9d15c7cb
MD5 65f1b551a3a457207b7385956f128bac
BLAKE2b-256 95b8546690d4b78471649d4b9ca42f6fd77c14ea6e8b22d88df1ea96fa23fb26

See more details on using hashes here.

File details

Details for the file atomix_stm-3.3.5-py3-none-any.whl.

File metadata

  • Download URL: atomix_stm-3.3.5-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.10

File hashes

Hashes for atomix_stm-3.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f480543946d28543ae6642757f70662edd44f8eb1aa4c141ca2e91dd7289e87a
MD5 9cff00ac27859e23dc8b57b4640e2a18
BLAKE2b-256 c9a232311f7f097f5d04ff5af316a1791c0fc87a0bb0c4e83bd5caaaa68c247a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page