Extracted the dependency injection process from fastapi.
Project description
fastapi_di
Extracted the dependency injection process from fastapi. Dependency injection by fastapi_di is only available in the async environment.
Requirement
- Python 3.8+
Installation
poetry install fastapi_di
Getting started
Dependency injection is done by decorating the function and calling do as follows.
import asyncio
from fastapi import Depends
from fastapi_di import DI
di = DI()
def get_db():
yield {1: {"id": 1, "name": "bob", "memo": ""}}
@di.task()
async def update_user(db=Depends(get_db), *, user_id: int, memo: str):
record = db[user_id]
record["memo"] = memo
return record
async def main():
return await update_user.do(user_id=1, memo="test")
result = asyncio.run(main())
print(result)
# => {'id': 1, 'name': 'bob', 'memo': 'test'}}
warning
This library is in the experimental stage.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_di-0.0.1.tar.gz
(6.8 kB
view details)
Built Distribution
File details
Details for the file fastapi_di-0.0.1.tar.gz
.
File metadata
- Download URL: fastapi_di-0.0.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.8 CPython/3.8.5 Linux/5.8.0-48-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8bb267a5e8b3c668828d9e22cc54801e0219619c2844f1c1f9cb4f58384a1d9 |
|
MD5 | bbdea113f0ec5a092220a95381063713 |
|
BLAKE2b-256 | 4d2f7f1d20c1d2b7a660126d67ba8e9c684117cced614774fadfd2b7b4923882 |
File details
Details for the file fastapi_di-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: fastapi_di-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.8 CPython/3.8.5 Linux/5.8.0-48-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb23fb8cf1972fbed1590013a6eb7fed6ec6330746aa9130a88d9d35ee5e082e |
|
MD5 | 76d301f8153b32adead27c4f69980e79 |
|
BLAKE2b-256 | 3aaa7f44bbadcf5591ff5e51aaaa7d2fdab8492d51f65f0a0735a696677e4e81 |