Skip to main content

A distributed lock implementation based on SQLAlchemy

Project description

SQLAlchemy-DLock

Distributed lock based on Database and SQLAlchemy.

It currently supports locks of:

It's not stable and DO NOT use it in production.

Usages

Basic:

from sqlalchemy import create_engine
from sqlalchemy_dlock import make_session_level_lock as sd_lock

# ...

lock_key = 'user/001'

# ...

engine = create_engine()

# ...

with engine.connect() as conn:
    with sd_lock(conn, lock_key):
        # do sth...
        pass
# ...

Made from SQLAlchemy's Session:

# ...

lock_key = 'user/001'

# ...

with Session.bind.connect() as conn:
    with sd_lock(conn, lock_key):
        # ...
        user = Session.query(User).filter(id='001').one()
        user.password = new_pass
        Session.commit()
        # ...
# ...

Or, if the session has no commit, rollback, close:

# ...

lock_key = 'user/001'

# ...

with sd_lock(Session.connection(), lock_key):
    # ...
    user = Session.query(User).filter(id='001').one()
    password = user.password
    # ...
# ...

CHANGELOG

v0.1.1

  • An early version, maybe not stable enough.
  • Replace black2b with crc64-iso in PostgreSQL key convert function

AUTHORS

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

SQLAlchemy-DLock-0.1.1.tar.gz (21.4 kB view hashes)

Uploaded Source

Built Distribution

SQLAlchemy_DLock-0.1.1-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

Supported by

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