FastDepends - FastAPI Dependency Injection system extracted from FastAPI and cleared of all HTTP logic. Async and sync modes are both supported.
MIT License
Bot releases are hidden (Show)
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.4.1...2.4.2
Published by Lancetnik 8 months ago
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.4.0...2.4.1
Published by Lancetnik 8 months ago
fast_depends.shema.get_schema
method to generate wrapped function payload (close https://github.com/Lancetnik/FastDepends/issues/6)ForwardRef
resolutionFull Changelog: https://github.com/Lancetnik/FastDepends/compare/2.3.1...0.2.4
Published by Lancetnik 9 months ago
fast_depends.shema.get_schema
method to generate wrapped function payload (close #6)Waiting for FastStream update to release stable version
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.3.1...0.2.4b0
Published by Lancetnik 9 months ago
Correct model.flat_params
calculation
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.3.0...2.3.1
Published by Lancetnik 10 months ago
Annotated
arguments support:
from typing import Annotated
from annotated_types import Ge
from pydantic.functional_validators import AfterValidator
@inject()
def f(a: Annotated[int, Ge(10), AfterValidator(lambda x: x + 10)]) -> int:
return a
assert f(10) == 20
@inject
def simple_func(a: str) -> Iterator[int]:
for _ in range(2):
yield a
for i in simple_func("1"):
assert i == 1
CustomField
with async use_field
in parallelFull Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.8...2.3.0
Published by Lancetnik 10 months ago
Restore fast_depends._compat.CreateBaseModel
to save FastStream<0.3.7 compatibility
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.7...2.2.8
Published by Lancetnik 10 months ago
from fast_depends import inject, Depends, dependency_provider
def dep1():
yield 1
def dep2():
yield 2
@inject()
def func(d = Depends(dep1)):
return d
assert func() == 1
with dependency_provider.scope(dep1, dep2):
assert func() == 2
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.6...2.2.7
Published by Lancetnik 10 months ago
Provides you with the ability to setup pydantic config using @inject
@inject(pydantic_config={"str_max_length": 8})
def limited_str(a: str):
...
limited_str("*" * 9) # raises ValidationError
Also, added context manager method to override dependencies:
from fast_depends import Depends, dependency_provider, inject
def base_dep():
return 1
def override_dep():
return 2
@inject
def func(d=Depends(base_dep)):
return d
with dependency_provider.scope(base_dep, override_dep):
assert func() == 2
assert func() == 1
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.5...2.2.6
Published by Lancetnik 10 months ago
New CustomField
syntax to support classes injection:
class Header(CustomField):
def use(
self,
/, # <- new thing
**kwargs
):
kwargs = super().use(**kwargs)
kwargs[self.param_name] = kwargs["headers"][self.param_name]
return kwargs
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.4...2.2.5
Published by Lancetnik 10 months ago
Now you can use FastDepends to inject dependencies to your class constructors and/or methods!
from fast_depends import Depends, inject
def get_var():
return 1
class Class:
@inject
def __init__(self, a = Depends(get_var)) -> None:
self.a = a
@inject
def calc(self, a = Depends(get_var)) -> int:
return a + self.a
assert Class().calc() == 2
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.3...2.2.4
Published by Lancetnik 11 months ago
Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.0...2.2.3
Published by Lancetnik about 1 year ago
With this release, async and sync generator function support was added!
This case supports incoming and return types casting both
from fast_depends import inject
@inject
def func(a: str) -> int:
for _ in range(3)
yield a
for i in func(1):
assert i == "1"
Also, @inject
has an option to disable pydantic validation with cast=False
. This way Depends
and your custom fields are still working, but pydantic is not even called.
from fast_depends import inject
@inject(cast=False)
def func(a: str) -> int:
return a
assert func(1.0) == 1.0
Published by Lancetnik over 1 year ago
Now the package is able to validate not only a final decraled fields, but also an *args, **kwargs
too!
@inject
def simple_func(
a: int,
*args: Tuple[float, ...],
b: int,
**kwargs: Dict[str, int],
):
...
This way, the all function variaty is supported
Published by Lancetnik over 1 year ago
Stable and fulltested PydanticV2 and PydanticV1 both supporting!
Published by Lancetnik over 1 year ago
It is a totally new package with the same testcases and public interfaces!
It works with pydanticV1
and pydanticV2.0b3
both, so you can easy migrate to beta pydanticV2 Rust
version and increase performance by 2-50x!
Published by Lancetnik over 1 year ago
Now you are able to create your own Header, Path, BackgroundTasks or anything you wish fields with a custom behavior.
Take a look at the docs for details.
Published by Lancetnik over 1 year ago
Includes:
Depends
class with nestingRelease is 100% tested, all actual by 0.95.0 FastAPI version features are supported.
Just download and enjoy this package.
Full Changelog: https://github.com/Lancetnik/FastDepends/commits/1.0.0