Skip to main content

Core library for RPA processes in AAK-MBU

Project description

MBU-rpa-core

Core library for RPA processes.

mbu_rpa_core provides shared building blocks that RPA processes in the MBU department can rely on: a managed database connection, helpers for constants and encrypted credentials, heartbeat and event logging, symmetric encryption, custom exception types, and standardized process completion states.

Features

  • Managed database connectionRPAConnection is a context manager wrapping a pyodbc connection with automatic commit/rollback on exit.
  • Constants and credentials store – helpers to add, fetch, and update application constants and encrypted credentials in the RPA database.
  • Event and heartbeat logging – write log entries and service heartbeats to the RPA database, and read them back.
  • Stored procedure execution – call stored procedures with typed parameters and get a structured result back.
  • Fernet encryptionEncryptor for symmetric encryption/decryption of sensitive values such as passwords.
  • Custom RPA exceptionsBusinessError and ProcessError (both inheriting from BaseRPAError) with Pydantic validation.
  • Process completion statesCompletedState model with completed / completed_with_exception factory methods.

Project structure

mbu_rpa_core/
├── database/
│   ├── connection.py     # RPAConnection context manager
│   ├── constants.py      # Constants and credentials helpers
│   ├── logging.py        # Event logging and heartbeats
│   └── utility.py        # execute_query / execute_stored_procedure
├── utils/
│   └── fernet_encryptor.py
├── tests/
├── exceptions.py         # BaseRPAError, BusinessError, ProcessError
└── process_states.py     # CompletedState, StateType

Installation

pip install mbu_rpa_core

Requires Python 3.8 or newer. Runtime dependencies: pydantic>=2.0.0, pyodbc, python-dateutil, python-dotenv, cryptography.

Usage

Opening a connection

RPAConnection must be used as a context manager. Work committed only if commit=True is passed; otherwise the transaction is rolled back on exit.

from mbu_rpa_core.database import RPAConnection

with RPAConnection(db_env="PROD", commit=True) as rpa_conn:
    rpa_conn.add_constant("MyConstant", "some value")

Constants

with RPAConnection(db_env="TEST", commit=True) as rpa_conn:
    rpa_conn.add_constant("RetryLimit", "3")
    value = rpa_conn.get_constant("RetryLimit")
    rpa_conn.update_constant("RetryLimit", "5")

Credentials (encrypted passwords)

with RPAConnection(db_env="PROD", commit=True) as rpa_conn:
    rpa_conn.add_credential("ServiceAccount", username="svc_user", password="s3cret")
    creds = rpa_conn.get_credential("ServiceAccount")
    # creds = {"username": ..., "decrypted_password": ..., "encrypted_password": ...}

Executing queries and stored procedures

with RPAConnection(db_env="PROD", commit=False) as rpa_conn:
    rows = rpa_conn.execute_query(
        "SELECT id, name FROM [test] WHERE active = ?",
        params=[1],
        return_dict=True,
    )

    result = rpa_conn.execute_stored_procedure(
        stored_procedure="rpa.sp_DoWork",
        params={
            "ItemId": (int, 42),
            "Payload": ("json", {"key": "value"}),
        },
    )
    # result = {"success": True, "error_message": None, "rows_updated": ...}

Stored-procedure parameters are passed as a dict where each value is a (type, value) tuple. Supported type keys are "str", "int", "float", "datetime" (parsed with dateutil), and "json" (serialized via json.dumps).

Event logging and heartbeats

with RPAConnection(db_env="PROD", commit=True) as rpa_conn:
    rpa_conn.log_event(
        log_db="Logs",
        level="INFO",
        message="Process started",
        context="MyProcess",
    )
    latest = rpa_conn.get_latest_log(log_db="rpa.Logs")

    # Send a heartbeat loop (runs until `stop` becomes True)
    rpa_conn.log_heartbeat(
        stop=False,
        servicename="MyProcess",
        heartbeat_interval=30,
        details="main loop",
    )

Encryption

from mbu_rpa_core.utils.fernet_encryptor import Encryptor

encryptor = Encryptor()
token = encryptor.encrypt("my secret")
plaintext = encryptor.decrypt(token)

Exceptions and process states

from mbu_rpa_core.exceptions import BusinessError, ProcessError
from mbu_rpa_core.process_states import CompletedState

# Raise domain-specific errors
raise BusinessError("Invoice number is missing")
raise ProcessError("Upstream service did not respond")

# Report process outcome
state = CompletedState.completed("All 120 records processed")
state_with_issues = CompletedState.completed_with_exception("3 records skipped")

Development

Install the package with its development extras and run the test suite:

pip install -e ".[dev]"
pytest

The repository ships with GitHub Actions workflows for linting (pylint), unit tests, version-number validation on PRs, release branch creation, and publishing to PyPI.

License

Released under the MIT License.

Repository

https://github.com/AAK-MBU/MBU-rpa-core

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

mbu_rpa_core-0.2.5.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

mbu_rpa_core-0.2.5-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file mbu_rpa_core-0.2.5.tar.gz.

File metadata

  • Download URL: mbu_rpa_core-0.2.5.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mbu_rpa_core-0.2.5.tar.gz
Algorithm Hash digest
SHA256 5580e31ee0314d1de7b4b873bb8bbb03b0d82ce3548b6123a922c85a92d3d3d8
MD5 a833a0a66c411d4a719a073139f895c7
BLAKE2b-256 00d37680deddda01af4258d0cd0c3972c4d56dc1cb1ebb7a0501cb625b6fbfb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbu_rpa_core-0.2.5.tar.gz:

Publisher: publish_to_pypi.yml on AAK-MBU/MBU-rpa-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mbu_rpa_core-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: mbu_rpa_core-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mbu_rpa_core-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1074542c97202e46384cb8ee7beda114338af65ad8c24ed42e92a4f175b27b9d
MD5 afccb1a0216b2a36a43417f6c0b9e75b
BLAKE2b-256 28d501ab2778af07c2a291a134e1e7ac7f8c5ddc0e8faf5bab9d0d94eb7250a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbu_rpa_core-0.2.5-py3-none-any.whl:

Publisher: publish_to_pypi.yml on AAK-MBU/MBU-rpa-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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