Skip to main content

A distributed lock implementation based on SQLAlchemy

Project description

SQLAlchemy-DLock

Documentation Status

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 usage:

# ...
from sqlalchemy import create_engine
from sqlalchemy_dlock import make_sa_dlock

# ...

lock_key = 'user/001'

# ...

engine = create_engine('postgresql://scott:tiger@localhost/')

# ...

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

Work with SQLAlchemy's Session:

# ...
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_dlock import make_sa_dlock
# ...

lock_key = 'user/001'

# ...

engine = create_engine('postgresql://scott:tiger@localhost/')
Session = sessionmaker(bind=engine)

# ...

session = Session()

# ...

with session.bind.connect() as conn:
    with make_sa_dlock(conn, lock_key):
        # ...
        user = session.query('User').filter(id='001').one()
        user.password = 'new password'
        session.commit()
        # ...
# ...

CHANGELOG

v0.1.2

Date: 2021-01-26

Still an early version, not for production.

  • Changes:
    • Arguments and it's default value of acquire now similar to stdlib's multiprossing.Lock, instead of Threading.Lock
    • MySQL lock now accepts float-point value as timeout
  • Adds
    • Several new test cases
  • Other
    • Many other small adjustment

v0.1.1

  • A very early version, maybe not stable enough.
  • Replace black2b with crc64-iso in PostgreSQL key convert function
  • Only named arguments as extra parameters allowed in Lock's implementation class

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.2.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

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

SQLAlchemy_DLock-0.1.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file SQLAlchemy-DLock-0.1.2.tar.gz.

File metadata

  • Download URL: SQLAlchemy-DLock-0.1.2.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for SQLAlchemy-DLock-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fc92d5260e7557e32f2a1fa0c30c26a0bfddf41f59d826818739390f71bcfd01
MD5 c1691631e333abf6958a8b1f30c2f554
BLAKE2b-256 fc1d919957865b53970d59b75a33db5545e3bd780a071c0a3beb06f8f433c13c

See more details on using hashes here.

File details

Details for the file SQLAlchemy_DLock-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: SQLAlchemy_DLock-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for SQLAlchemy_DLock-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 edbef92d4a29faae02642514101b877b09809ea62eae4760e6dbb88ff80db830
MD5 39d3a7d9fc62fc9d9aaae379895fa2bf
BLAKE2b-256 6cad5dccaf54b14d689a9eaeeed0dde281a3d6bf2478e6f0fe914216c55382ba

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