Skip to main content

A simple rules engine package for python

Project description

py flow rules

License: MIT Python Version PyPI version CI Status Coverage Code style: black Downloads

A simple rules engine implementation for python.


Features

  • Allows the developer to write simple rules policies to aggregate the business logic for an application.

Installation

Clone this repository and install the necessary dependencies.

git clone https://github.com/p1971/pyFlowRules.git
cd pyFlowRules
python -m venv .venv
source .venv/bin/activate  # On Windows use: .\.venv\Scripts\activate

# For core functionality only (no dependencies required):
pip install -e .

# For development (includes testing tools):
pip install -r requirements-dev.txt

# For running examples:
pip install -r requirements-examples.txt

Make sure you have Python 3.10 or above installed.

Versioning

This project follows Semantic Versioning. Version numbers are in the format MAJOR.MINOR.PATCH:

  • MAJOR version for incompatible API changes
  • MINOR version for added functionality in a backwards compatible manner
  • PATCH version for backwards compatible bug fixes

Current version: PyPI

Requirements Files

The project uses separate requirements files for different purposes:

  • requirements.txt - Core dependencies (currently empty as we only use standard library)
  • requirements-dev.txt - Development dependencies (pytest, coverage, etc.)
  • requirements-examples.txt - Dependencies for running example code

Usage

Here is an example of how to use the project:

from dataclasses import dataclass

from flowrules.rules_engine import policy, rule, Policy

@dataclass
class Request:
    id: int
    notional: float
    client: str
    
@policy(policy_id="P01", policy_name="InitialRequestValidation")
class InitialRequestPolicy(Policy):
    @rule(rule_id="R001", rule_name="Validate notional", failure_message="The notional is too high.")
    def validate_notional(self, r: Request):
        return r.notional < 100000
    
    @rule(rule_id="R002", rule_name="Validate client", failure_message="The client is unknown.")
    def validate_client(self, r: Request):
        return r.client in ["client1", "client2"]
  

policy = InitialRequestPolicy()
result = policy.execute(Request(id=1, notional=90000, client="client1"))
print(result)

You can find more examples in the examples/ directory. For example

python -m example.main

Running Tests

Unit tests are included for this project. Use pytest to run them (recommended):

pip install pytest  # Install pytest if not already done
pytest

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push your branch (git push origin feature/your-feature).
  5. Open a pull request.

Make sure your code passes all tests and follows Python best practices.


License

This project is licensed under the MIT License - see the LICENSE file for details.


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

py_flow_rules-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

py_flow_rules-1.0.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file py_flow_rules-1.0.0.tar.gz.

File metadata

  • Download URL: py_flow_rules-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for py_flow_rules-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d3e64338edac7857b6edc4824e712f5bf8b438c5a06f9b64667047a6c155ebea
MD5 3f15e1cc7599a26b2b9807e031e25c8d
BLAKE2b-256 4ca224861ce4536f9c5ac773e94156f50b87beb69558f512d40276808f1978fc

See more details on using hashes here.

File details

Details for the file py_flow_rules-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_flow_rules-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for py_flow_rules-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5909ce9160558de09e9164a41a0b41731ec31026b8a1f354ec4df1b0fab9e7e
MD5 b105ba0802949b2e045fdf60461df0b7
BLAKE2b-256 bbff6a230eda552213974d3fe1fd565b8f1b9375c25c3d4bcc221f25ed4c168e

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