{"id":15297367,"url":"https://github.com/ceppelli/magic_foundation","last_synced_at":"2026-01-21T17:02:13.404Z","repository":{"id":49633131,"uuid":"273276370","full_name":"ceppelli/magic_foundation","owner":"ceppelli","description":"Minimalistic library that simplifies the adoption of async/await (asyncio) programming style in a multithreaded application.","archived":false,"fork":false,"pushed_at":"2021-06-11T18:11:52.000Z","size":32,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-26T08:45:44.980Z","etag":null,"topics":["async","asyncio","await-async","framework","multithreading","publish-subscribe","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ceppelli.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}},"created_at":"2020-06-18T15:37:08.000Z","updated_at":"2023-03-02T08:06:05.000Z","dependencies_parsed_at":"2022-09-26T17:11:41.467Z","dependency_job_id":null,"html_url":"https://github.com/ceppelli/magic_foundation","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ceppelli/magic_foundation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceppelli%2Fmagic_foundation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceppelli%2Fmagic_foundation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceppelli%2Fmagic_foundation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceppelli%2Fmagic_foundation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ceppelli","download_url":"https://codeload.github.com/ceppelli/magic_foundation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceppelli%2Fmagic_foundation/sbom","scorecard":{"id":271117,"data":{"date":"2025-08-11","repo":{"name":"github.com/ceppelli/magic_foundation","commit":"4d3b42a294cdd85056030af06920e9dfb33dfad3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/12 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/python-publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/ceppelli/magic_foundation/python-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/ceppelli/magic_foundation/python-publish.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/python-publish.yml:23","Warn: pipCommand not pinned by hash: .github/workflows/python-publish.yml:24","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 3-Clause \"New\" or \"Revised\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2021-95 / GHSA-8ch4-58qp-g3mp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T13:22:32.873Z","repository_id":49633131,"created_at":"2025-08-17T13:22:32.873Z","updated_at":"2025-08-17T13:22:32.873Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28636647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T15:01:31.228Z","status":"ssl_error","status_checked_at":"2026-01-21T14:42:58.942Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["async","asyncio","await-async","framework","multithreading","publish-subscribe","python3"],"created_at":"2024-09-30T19:16:56.247Z","updated_at":"2026-01-21T17:02:13.368Z","avatar_url":"https://github.com/ceppelli.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## magic_foundation\n\n[![Build Status](https://travis-ci.com/ceppelli/magic_foundation.svg?branch=master)](https://travis-ci.com/ceppelli/magic_foundation)\n[![codecov](https://codecov.io/gh/ceppelli/magic_foundation/branch/master/graph/badge.svg)](https://codecov.io/gh/ceppelli/magic_foundation)\n[![pypi](https://badge.fury.io/py/magic-foundation.svg)](https://pypi.org/project/magic_foundation/)\n\n\nMinimalistic library that simplifies the adoption of **async/await** (asyncio) programming style in a multithreaded application.\n\n\nDefine 2 services and run in the same runloop (single thread)\n\n```python\nimport logging\n\nfrom magic_foundation import Service, ServiceStatus, ServiceContext, Main\n\n\nclass TestService(Service):\n\n  def __init__(self, name:str):\n      self.name = name\n\n  async def initialize(self, ctx:ServiceContext):\n    log.info(f\"[{self.name}] initialize\")\n    \n  async def run(self, ctx:ServiceContext):\n    index = 0\n\n    while self.status is ServiceStatus.running:\n      log.info(f\"[{self.name}] run {index}\")\n      index += 1\n      await asyncio.sleep(1.0)\n\n  async def terminate(self, ctx:ServiceContext):\n    log.info(f\"[{self.name}] terminate\")\n\n\nif __name__ == \"__main__\":\n  log = logging.getLogger(__name__)\n  logging.basicConfig(level=logging.INFO)\n  logging.getLogger(\"magic_foundation\").setLevel(logging.DEBUG)\n\n  main = Main.instance()\n  main.service_pools = {\n    'main': [\n      TestService(name=\"Service_1\"),\n      TestService(name=\"Service_2\")\n    ],\n  }\n  main.run()\n\n```\n\nIf you want running the 2 services in different threads just define the service_pools as following:\n\n```python\n\n  ...\n  main = Main.instance()\n  main.service_pools = {\n    'th1': [\n      TestService(name=\"Service_1\")\n    ],\n    'th2': [\n      TestService(name=\"Service_2\")\n    ],\n  }\n  main.run()\n\n```\n\n\n## Communication\n\nThe communication between Services mimics the **publish/subscribe paradigm**\n\n**Subscribe**\n\n```python\n\n  async def coro(data):\n    log.info(f\"[{self.name}] coro data:{data}\")\n\n  await ctx.subscribe(queue_name=\"q://my_queue\", handler=coro)\n\n```\n\n\n**Pubblish**\n\n\n```python\n\n  data = {\n    \"a\": \"A\",\n    \"b\": 1234 \n  }\n  \n  await ctx.publish(queue_name=\"q://my_queue\", data=data) \n\n```\n\nIt is possible to subscribe to the same queue from different services and each service will receive the message\n\n\n## WebSocket Service\n\nAs an additionan component the library provides a built-in websocket service.\n\n```python\n\nfrom magic_foundation import Container, Service, ServiceStatus, ServiceContext, Main\nfrom magic_foundation.websocket_service import WebSocketService\n\n...\n\nclass TestService(Service):\n\n  ...  \n    \n  async def run(self, ctx:ServiceContext):\n    log.info(f\"[{self.name}] run\")\n\n    async def handler(data):\n      log.info(f\"[{self.name}] handler inbound data:{data}\")\n      req = json.loads(data)\n      res = json.dumps({\"status\": \"OK\", \"timestamp\": req[\"timestamp\"]})\n      await ctx.publish(queue_name=\"ws://outbound/client\", data=res)\n\n    await ctx.subscribe(queue_name=\"ws://inbound/client\", handler=handler)\n\n    ...\n\n  async def terminate(self, ctx:ServiceContext):\n    log.info(f\"[{self.name}] terminate\")\n...\n\n\nif __name__ == \"__main__\":\n    main = Main.instance()\n\n    main.service_pools = {\n      \"main\" : [\n        WebSocketService(host=\"localhost\", port=8765),\n        TestService(name=\"Consumer\"), \n      ]\n    }\n\n    main.run()\n```\n\nThe prefixes **ws://inbound/** and **ws://outbound/** refer to the WS endpoint (WebSocketService) and **must be considered reserved**.\n\nThe complete example is contained in the examples folder. \n\nTo trying it run in a shell the command: **python examples/websocket.py** and in a browser open the file **websocket.html**. \n\n### Limitations\n\nRight now only the requested **path** is use as discriminant, so messages from different clients with the same path are routed to the same handler and vice versa one outbound message is sent to all clients connected to the same **path**.\n\n\n## Simple Logging Service\n\nThe included logging service is a simpple way to dump json maggase to a local file.\n\n```python\n\nfrom magic_foundation import Container, Service, ServiceStatus, ServiceContext, Main\nfrom magic_foundation.logging_service import LoggingService\n\n...\n\nfile_path = \"logging_out.log\"\n\nclass TestService(Service):\n\n  ...  \n    \n  async def run(self, ctx:ServiceContext):\n    log.info(f\"[{self.name}] run\")\n\n    ...\n\n  async def terminate(self, ctx:ServiceContext):\n    log.info(f\"[{self.name}] terminate\")\n\n    index = 0;\n\n    while self.status == ServiceStatus.running:\n      index += 1\n      data = {\"cmd\": \"log\", \"index\": index}\n\n      await ctx.publish(queue_name=f\"log://{file_path}\", data=data)\n\n      await asyncio.sleep(1.0)\n...\n\n\nif __name__ == \"__main__\":\n    main = Main.instance()\n\n    main.service_pools = {\n      \"backgound\" : [\n        LoggingService(file_path=file_path, flush_interval_sec=4.0)\n      ],\n      \"main\" : [\n        TestService(name=\"Producer\")\n      ]\n    }\n\n    main.run()\n```\n\nThe prefixes **log://** refers to the simple logging service (LoggingService) and **must be considered reserved**.\n\nThe complete example is contained in the examples folder. \n\nTo trying it run in a shell the command: **python examples/dump_to_file.py**. In the root of the project a file called **logging_out.log** will be created and every 4 seconds the logging service will flush the collected messages. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceppelli%2Fmagic_foundation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceppelli%2Fmagic_foundation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceppelli%2Fmagic_foundation/lists"}