Skip to main content

Alchemytools is a set of helpers to be used in any SQLAlchemy project

Project description

This project brings a set of useful tools to be used in any SQLAchemly project.

The idea is to save common problems, for example: Opening/Closing sessions, commiting the sesssin only at the end of the transaction, etc.

Available Tools

Here are all tools available in alchemytools.

Context Managers

managed

This is the basic context manager and it will commit and close your session automatically, at the end of the with block.

with managed(MySessionClass) as session:
    # Do what you need with your session
# Here the session is already closed and commited

If you raise any exception inside the with block, the session will be rolled back and the exception re-raised.

Additional options
  • auto_flush: Sets the autoflush option on the SQLAlchemy session, defaults fo False

commit_on_success

This contextmanager should be used in an inner with block, where you already have an open session but need to commit more than one time. The code will be something on these lines.

with managed(MySession) as session:
    for a in iterable:
        with commit_on_success(session):
            process(a)
            session.add(a)

If you raise an exception inside the second with block, all previous iterations will already be commited and just the current one will be rolledback.

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

Alchemytools-0.2.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file Alchemytools-0.2.tar.gz.

File metadata

  • Download URL: Alchemytools-0.2.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Alchemytools-0.2.tar.gz
Algorithm Hash digest
SHA256 df6b148ebcb98eeaa8e1687b217beffd90c2eb095a168faf2e042917db6acd18
MD5 1de3a2815706057f7777b92556dcd80b
BLAKE2b-256 ca460375256eae4cc16db776e1ae9abb403115410d2d7d386104b89ca7e3090e

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