{"id":14979082,"url":"https://github.com/teamhide/fastapi-event","last_synced_at":"2025-07-04T10:03:34.249Z","repository":{"id":38198791,"uuid":"438657942","full_name":"teamhide/fastapi-event","owner":"teamhide","description":"Event dispatcher for FastAPI","archived":false,"fork":false,"pushed_at":"2022-09-02T05:27:59.000Z","size":28,"stargazers_count":50,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-29T02:21:44.865Z","etag":null,"topics":["asyncio","event-driven","event-emitter","eventbus","eventdispatcher","eventstore","fastapi","fastapi-event"],"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/teamhide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-15T14:25:23.000Z","updated_at":"2024-09-19T12:19:27.000Z","dependencies_parsed_at":"2022-07-12T17:12:25.263Z","dependency_job_id":null,"html_url":"https://github.com/teamhide/fastapi-event","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Ffastapi-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Ffastapi-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Ffastapi-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Ffastapi-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teamhide","download_url":"https://codeload.github.com/teamhide/fastapi-event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859520,"owners_count":16556036,"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":["asyncio","event-driven","event-emitter","eventbus","eventdispatcher","eventstore","fastapi","fastapi-event"],"created_at":"2024-09-24T13:59:12.088Z","updated_at":"2024-10-11T18:42:03.063Z","avatar_url":"https://github.com/teamhide.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastapi-event\n[![license]](/LICENSE)\n[![pypi]](https://pypi.org/project/fastapi-event/)\n[![pyversions]](http://pypi.python.org/pypi/fastapi-event)\n[![Downloads](https://pepy.tech/badge/fastapi-event)](https://pepy.tech/project/fastapi-event)\n\n---\n\nfastapi-event is event dispatcher for FastAPI framework.\n\n## Installation\n\n```python\npip3 install fastapi-event\n```\n\n## Usage\n\n### Make Event\n\n```python\nfrom fastapi_event import BaseEvent\n\n\nclass TestEvent(BaseEvent):\n    async def run(self, parameter=None):\n        ...\n```\n\nInherit `BaseEvent` and override `run()` method.\n\n```python\nfrom fastapi_event import BaseEvent\n\n\nclass FirstEvent(BaseEvent):\n    ORDER = 1  # HERE(Optional)\n    \n    async def run(self, parameter=None):\n        ...\n\n\nclass SecondEvent(BaseEvent):\n    ORDER = 2  # HERE(Optional)\n    \n    async def run(self, parameter=None):\n        ...\n```\n\nIf you want to determine the order between events, specify `ORDER` in your event. \n\nThen, regardless of the order in which the events are stored, they will be executed in the order specified in `ORDER` variable.\n\nHowever, `ORDER` does not work when `run_at_once=True`.\n\n### Parameter(optional)\n\n```python\nfrom pydantic import BaseModel\n\n\nclass TestEventParameter(BaseModel):\n    id: str\n    pw: str\n```\n\nIn case of need parameter, you have to inherit `BaseModel` and set fields.\n\n### Middleware\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_event import EventHandlerMiddleware\n\napp = FastAPI()\napp.add_middleware(EventHandlerMiddleware)\n```\n\n### EventListener\n\n```python\nfrom fastapi_event import EventListener\n\n\n@EventListener()\nasync def test():\n    ...\n```\n\nSet `@EventListener()` decorator on the function that emits the event.\n\n```python\n@EventListener(run_at_once=False)\n```\n\nIf you pass `run_at_once=False`, it will execute in the order in which `store()` is called. (or according to the `ORDER` variable defined in the event)\n\nOtherwise, it will execute through `asyncio.gather()` to run at once.\n\n### Store event\n\n```python\nfrom fastapi_event import EventListener, event_handler\n\n\n@EventListener()\nasync def test():\n    await event_handler.store(\n        event=TestEvent,\n        parameter=TestParameter(id=\"hide\", pw=\"hide\"),  # Optional\n    )\n```\n\nStore your event to handler via `store()` method. (parameter is optional)\n\nAn event will be emitted after the function has finished executing.\n\n[license]: https://img.shields.io/badge/License-Apache%202.0-blue.svg\n[pypi]: https://img.shields.io/pypi/v/fastapi-event\n[pyversions]: https://img.shields.io/pypi/pyversions/fastapi-event\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamhide%2Ffastapi-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteamhide%2Ffastapi-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamhide%2Ffastapi-event/lists"}