FastDepends - extracted and cleared from HTTP domain Fastapi Dependency Injection System
Project description
FastDI
Documentation: https://lancetnik.github.io/FastDI/
FastDI - extracted and cleared from HTTP domain logic Fastapi Dependency Injection System. This is a little library, providing you ability to use lovely Fastapi interfaces at your own projects or tools.
Thanks to fastapi and pytest projects for this greate functional. This package just a little change Fasapi sources to provide DI functionality pyre-python way.
Usage
There is no way to make Dependency Injection easier
You can use this library without any frameworks at sync and async code both
Async code
import asyncio
from fastdi import inject, Depends
async def dependency(a: int) -> int:
return a
@inject
async def main(
a: int,
b: int,
c: int = Depends(dependency)
) -> float:
return a + b + c
assert asyncio.run(main("1", 2)) == 4.0
Sync code
from fastdi import inject, Depends
def dependency(a: int) -> int:
return a
@inject
def main(
a: int,
b: int,
c: int = Depends(dependency)
) -> float:
return a + b + c
assert main("1", 2) == 4.0
@inject
decorator playing multiple roles at the same time:
- resolve Depends classes
- cast types according python annotation
- validate incoming parameters using pydantic
Features
Syncronous code is fully supported at this package: without any async_to_sync
, run_sync
, syncify
or any another tricks.
Also, FastDI casts function return the same way, it can be very felpfull to build your own tools.
There is two main defferences from native Fastapi DI System.
Note
Library was build by actual 0.95.0 FastAPI version.
If we'll be too far behind, please, contact me or contubute yourself. Really appreciate your help.
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
Built Distribution
Hashes for fast_depends-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9d6f173f35e41841cb24cdb82517325908194387cf7ef924735f8d37e362af3 |
|
MD5 | 81a0d3b10734a587b2efb941cc1c39aa |
|
BLAKE2b-256 | 0d367b5d08875abd6247a8a854517c02ab73c6fbda7b094f00e5e2754cf4fc9b |