Skip to main content

Python Rules - Logic for SQLAlchemy

This package enables you to declare rules that govern SQLAlchemy update transaction logic (multi-table derivations, constraints, and actions such as sending mail or messages).

Logic is stated in Python, and is over an 40X more concise than code.

Features

Logic is declared in Python (example below), and is:

  • Extensible: logic consists of rules (see below), plus standard Python code

  • Multi-table: rules like sum automate multi-table transactions

  • Scalable: rules are pruned and optimized; for example, sums are processed as 1 row adjustment updates, rather than expensive SQL aggregate queries

  • Manageable: develop and debug your rules in IDEs, manage it in SCS systems (such as git) using existing procedures

Example:

The following 5 rules represent the same logic as 200 lines of Python:

https://github.com/valhuber/LogicBank/raw/main/images/example.png

To activate the rules declared above:

LogicBank.activate(session=session, activator=declare_logic)

Depends on:

  • SQLAlchemy

  • Python 3.8

More information:

The github project includes documentation and examples.

Acknowledgements

Many thanks to

  • Tyler Band, for testing and the Banking sample

  • Max Tardiveau, for testing

  • Nishanth Shyamsundar, for testing

  • Achim Götz, for design collaboration

Change Log

0.0.6 - Initial Version

0.0.7 - Class Name can differ from Table Name

0.0.8 - Much-reduced pip-install dependencies

0.0.9 - Hybrid attribute support, old_row example

0.1.0 - Hybrid attribute support, bug fix

0.1.1 - Allocation example - allocate a payment to a set of outstanding orders

0.2.0 - Minor design refactoring of allocation

0.3.0 - Include logic_bank.extensions (allocation), constraint exceptions raised as ConstraintExceptions

0.4.0 - Eliminate “engine” from runtime, to facilitate use in servers. Rework nw tests to centralize open logic in setup().

0.5.0 - Support for Referential Integrity, with examples.

0.5.1 - Support domain object constructors with complex (side effects) __init__ behavior; use row_mapper.column_attrs (not all_orm_descriptors) to avoid ‘flush already in progress’ when using flask_sqlalchemy

0.6.0 - Support for

  • Rule Extensibility

    • e.g., for auditing

  • Generic early events: early_row_event_all_classes (see Rule Extensibility link above)

    • e.g., for time/date stamping

  • New LogicRow functions (see Rule Extensibility link above):

    • are_attributes_changed

    • set_same_named_attributes

  • Minor rename of logic class in nw. Some screen shots may still show the old name (rules_bank.py) instead of logic.py.

  • Bug Fix: (normal) row events weren’t firing (other events - early and commit events - were fine)

0.7.0 - Custom Exceptions, Improved docstrings, samples (and Tutorial) reorganized into examples folder

0.8.0 - Custom Exceptions, callback signature changed to include additional parameters

0.9.0 - Add logicRow.get_derived_attributes, which can be used to enforce behaviors such as Unalterable Derivations

0.9.2 - Add session to logic_row.__str__(), listeners

0.9.3 - Allow for nulls in summed/sum

0.9.4 - Fix bad Warning: Missing Parent:

0.9.5 - Reduce requirement to initialize summed field

0.9.6 - Show Constraint Failures in Console Log

1.0.2 - Replace print with logging for listing rules

Release files for logicbank 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logicbank 1.0.2
File Size Uploaded
logicbank-1.0.2.tar.gz 33.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logicbank 1.0.2
File Interpreter ABI Platform
logicbank-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 75.6 kB

Release files / logicbank-1.0.2.tar.gz

Download URL logicbank-1.0.2.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5a7c4bcf8a599177e1be835ff9c7423624e30bd4e14ec7e9bff09c3c67f25e46
BLAKE2b-256 checksum
How to use checksums
02257f7e0245e7646caa7f01fc5c326386a1ba1ac0a7b352b745cb6bde997466
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

Release files / logicbank-1.0.2-py3-none-any.whl

Download URL logicbank-1.0.2-py3-none-any.whl
Size 42.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
451ab7384d2a8772e0a6065a195d72f5339af4be1aefd780183e7d08f64f1b9d
BLAKE2b-256 checksum
How to use checksums
3a12fa7135675bee2a0c567c166c8e386e3de223fde56c60be5e42de0ff241bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

Release history Release notifications | RSS feed

1.34.1

2 release files

1.34.0

2 release files

1.33.0

2 release files

1.32.0

2 release files

1.31.4

2 release files

1.31.3

2 release files

1.31.2

2 release files

1.31.1

2 release files

1.31.0

2 release files

1.30.2

2 release files

1.30.0

2 release files

1.20.8

2 release files

1.20.6

2 release files

1.20.5

2 release files

1.20.3

2 release files

1.20.2

2 release files

1.20.1

2 release files

1.19.0

2 release files

1.10.0

2 release files

1.8.5

2 release files

1.8.4

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.7

2 release files

1.6.6

2 release files

1.6.5

2 release files

1.6.4

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.0

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.0.7

2 release files

1.0.5

2 release files

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

3 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page