Skip to content

Commit

Permalink
update README; bump version to 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
melvinkcx committed Apr 6, 2023
1 parent 83016a0 commit 020af55
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
An event dispatching/handling library for FastAPI, and Starlette.

[![](https://github.com/melvinkcx/fastapi-events/actions/workflows/tests.yml/badge.svg?branch=dev&event=push)](https://github.com/melvinkcx/fastapi-events/actions/workflows/tests.yml)
![PyPI - Downloads](https://img.shields.io/pypi/dw/fastapi-events)

Features:

Expand All @@ -16,6 +17,9 @@ Features:
* (__>=0.4.0__) supports event chaining: dispatching events within handlers (thank [@ndopj](https://github.com/ndopj)
for contributing to the idea)
* (__>=0.7.0__) supports OpenTelemetry: see [this section](#opentelemetry-otel-support) for details
* (__>=0.9.0__) supports dependencies in local handlers: see [this section](#using-dependencies-in-local-handler) for details

If you use or like this project, please consider giving it a star so it can reach more developers. Thanks =)

## Installation

Expand Down Expand Up @@ -216,6 +220,42 @@ async def handle_all_events(event: Event):
pass
```

#### Using Dependencies in Local Handler

> new feature in fastapi-events>=0.9.0
Dependencies can now be used with local handler. Sub-dependencies are also supported.

However, dependencies using generator (with `yield` keyword) is not supported yet. I have the intention to support it in the future.


```python
# ex: in handlers.py
from fastapi import Depends

from fastapi_events.handlers.local import local_handler
from fastapi_events.typing import Event

async def get_db_conn():
pass # return a DB conn


async def get_db_session(
db_conn=Depends(get_db_conn)
):
pass # return a DB session created from `db_conn`



@local_handler.register(event_name="*")
async def handle_all_events(
event: Event,
db_session=Depends(get_db_session)
):
# use the `db_session` here
pass
```

### Piping Events To Remote Queues

For larger projects, you might have services dedicated to handling events separately.
Expand Down
2 changes: 1 addition & 1 deletion fastapi_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from fastapi_events.handlers.base import BaseEventHandler

__version__ = "0.8.0"
__version__ = "0.9.0"

# handlers keeps track of all handlers registered via EventHandlerASGIMiddleware
handler_store: Dict[int, Iterable[BaseEventHandler]] = defaultdict(list)
Expand Down

0 comments on commit 020af55

Please sign in to comment.