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.4.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.4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mbu_rpa_core-0.2.4.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.4.tar.gz
Algorithm Hash digest
SHA256 98699ef723ccf044bdbc72cd51cbdb9acdb19cc9473ed2525f1785e107e67506
MD5 0b5ef4cff5c7b8ad470f3f2a4c7d70dd
BLAKE2b-256 95da9068bf8e1cf567de5b06e248f913048695ce0270125af6c3b182288a6d8c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: mbu_rpa_core-0.2.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 73eda86e1dc710a69032a00ec05909e06fba2fac1ed972adbeaeba6af6a64fde
MD5 97ccd2222e98c9df9358d1fa45040708
BLAKE2b-256 25fe7cbe0f7b6aa7cfcefd854fc3cd36348ea338e7d64a93d32d53bf43b82090

See more details on using hashes here.

Provenance

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