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

An early version, maybe not stable enough.

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.tar.gz (20.4 kB view hashes)

Uploaded Source

Built Distribution

SQLAlchemy_DLock-0.1-py3-none-any.whl (9.9 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