{"id":17151234,"url":"https://github.com/soda480/mpcurses","last_synced_at":"2025-04-13T12:03:43.782Z","repository":{"id":38376934,"uuid":"260623813","full_name":"soda480/mpcurses","owner":"soda480","description":"Mpcurses is an abstraction of the Python curses and multiprocessing libraries providing function execution and runtime visualization capabilities.","archived":false,"fork":false,"pushed_at":"2025-01-04T21:35:19.000Z","size":8293,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-05T17:24:05.321Z","etag":null,"topics":["curses-screen","docker","multi-processing","pybuilder","python","queue"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soda480.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-02T05:55:26.000Z","updated_at":"2025-01-04T21:31:54.000Z","dependencies_parsed_at":"2023-11-25T04:24:37.144Z","dependency_job_id":"e5016e7a-35be-48b9-a48e-cc26e76655d1","html_url":"https://github.com/soda480/mpcurses","commit_stats":{"total_commits":56,"total_committers":2,"mean_commits":28.0,"dds":0.1071428571428571,"last_synced_commit":"01cf7d09a76d4184ff9b5403dedefc386ea4f0df"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fmpcurses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fmpcurses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fmpcurses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fmpcurses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soda480","download_url":"https://codeload.github.com/soda480/mpcurses/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240027414,"owners_count":19736210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curses-screen","docker","multi-processing","pybuilder","python","queue"],"created_at":"2024-10-14T21:37:34.209Z","updated_at":"2025-02-23T10:32:05.866Z","avatar_url":"https://github.com/soda480.png","language":"Python","readme":"# mpcurses\n[![build+test](https://github.com/soda480/mpcurses/actions/workflows/main.yml/badge.svg)](https://github.com/soda480/mpcurses/actions/workflows/main.yml)\n[![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://pybuilder.io/)\n[![complexity](https://img.shields.io/badge/complexity-A-brightgreen)](https://radon.readthedocs.io/en/latest/api.html#module-radon.complexity)\n[![vulnerabilities](https://img.shields.io/badge/vulnerabilities-None-brightgreen)](https://pypi.org/project/bandit/)\n[![PyPI version](https://badge.fury.io/py/mpcurses.svg)](https://badge.fury.io/py/mpcurses)\n[![python](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.12-teal)](https://www.python.org/downloads/)\n\nThe mpcurses package facilitates seamless terminal screen updates from child processes within a multiprocessing worker pool - leveraging the curses library for terminal manipulation. The `MPcurses` class is a subclass of [MPmq](https://pypi.org/project/mpmq/); a multiprocessing message queue which enables inter-process communication (IPC) between child workers and a parent process through queuing and consumption of log messages. Mpcurses provides a lightweight abstraction for the curses terminal screen, representing it as a Python dictionary. It includes predefined directives for updating the screen, encompassing:\n\n- Numeric counter management\n- Match messages using regular expressions\n- Text value and color updates\n- Visual indicator maintenance\n- Progress bar rendering\n- Table and list displays\n\n Refer to the MPcurses documentation here: https://soda480.github.io/mpcurses/\n\n### Installation\n```bash\npip install mpcurses\n```\n### Examples\n\nInvoke a single child process to execute a task defined by the `do_something` function. Mpcurses captures all log messages and sends them to a thread-safe queue, the main process consumes messages and uses regular expressions to update the screen which is represented as a dictionary.\n\n```python\nfrom mpcurses import MPcurses\nimport namegenerator, time, logging\nlogger = logging.getLogger(__name__)\n\ndef do_something(*args):\n    for _ in range(0, 400):\n        logger.debug(f'processing item \"{namegenerator.gen()}\"')\n        time.sleep(.01)\n\nMPcurses(\n    function=do_something,\n    screen_layout={\n        'display_item': {\n            'position': (1, 1), 'text': 'Processing:', 'text_color': 0, 'color': 14,\n            'clear': True, 'regex': r'^processing item \"(?P\u003cvalue\u003e.*)\"$'}\n    }).execute()\n ```\n\nExecuting the code above results in the following:\n![example](https://raw.githubusercontent.com/soda480/mpcurses/master/docs/images/demo.gif)\n\n**NOTE** none of the functions being executed in any of the examples include information about the curses screen, multiprocessing or messaging queue - this is handled seamlessly by mpcurses.\n\nBuild the Docker image using the instructions below, run the examples. `python examples/##/sample.py`\n\n#### [Prime Numbers Counter](https://github.com/soda480/mpcurses/blob/master/examples/03/sample.py)\n\nExecute a function that calculates prime numbers for a set range of integers. Execution is scaled across 7 different workers where each process computes the primes for a different range of numbers. For example, the first worker computes primes for the range 1-10K, second worker computes for the range 10K-20K, etc. The main process keeps track of the number of prime numbers encountered for each worker and shows overall progress for each worker using a progress bar.\n\n![example](https://raw.githubusercontent.com/soda480/mpcurses/master/docs/images/example3.gif)\n\n#### [Item Processor](https://github.com/soda480/mpcurses/blob/master/examples/06/sample.py)\n\nExecute a function that processes a list of random items. Execution is scaled across 3 workers where each worker processes a unique set of items. The main process maintains indicators showing the number of items that have been processed by each worker; counting the number of Successful, Errors and Warnings. Three lists are also maintained, one for each group that list which specific items had Warnings and Failures.\n\n![example](https://raw.githubusercontent.com/soda480/mpcurses/master/docs/images/example6.gif)\n\n#### [Bay Enclosure Firmware Update](https://github.com/soda480/mpcurses/blob/master/examples/09/sample.py)\n\nExecute a function that contains a workflow containing tasks to update firmware on a server residing in a blade enclosure. Execution is scaled across a worker pool with five active workers. The main process updates the screen showing status of each worker as they execute the workflow tasks for each blade server. \n\n![example](https://raw.githubusercontent.com/soda480/mpcurses/master/docs/images/example9.gif)\n\n### Projects using `mpcurses`\n\n* [edgexfoundry/sync-github-labels](https://github.com/edgexfoundry/cd-management/tree/git-label-sync) A script that synchronizes GitHub labels and milestones\n\n* [edgexfoundry/prune-github-tags](https://github.com/edgexfoundry/cd-management/tree/prune-github-tags) A script that prunes GitHub pre-release tags\n\n### Development\n\nClone the repository and ensure the latest version of Docker is installed on your development server.\n\nBuild the Docker image:\n```sh\ndocker image build \\\n-t mpcurses:latest .\n```\n\nRun the Docker container:\n```sh\ndocker container run \\\n--rm \\\n-it \\\n-v $PWD:/code \\\nmpcurses:latest \\\nbash\n```\n\nExecute the build:\n```sh\npyb -X\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoda480%2Fmpcurses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoda480%2Fmpcurses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoda480%2Fmpcurses/lists"}