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.3.tar.gz (5.3 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.3-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mbu_rpa_core-0.2.3.tar.gz
  • Upload date:
  • Size: 5.3 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.3.tar.gz
Algorithm Hash digest
SHA256 391d56516ae98df5e98cced314b38c63d89e875ff5dfaa58be77f95c4a1b05f2
MD5 9a26f1af76610d32b6e279339d5e959b
BLAKE2b-256 9978a9bc9044dfe89fe7333d37399ffc77d51a187717ab2b5394694e8675ec96

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbu_rpa_core-0.2.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: mbu_rpa_core-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.9 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e9bab35f7032997e5a1939923ad1759b21ebfa9e63ea774a4cc55979f85e4d4d
MD5 108b769d55fb51151f402c8034d7cd39
BLAKE2b-256 8a899d52c49632b65f935c194c12aac290c141d4ddb673e3d937542f0003844b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbu_rpa_core-0.2.3-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