FastDepends

FastDepends - FastAPI Dependency Injection system extracted from FastAPI and cleared of all HTTP logic. Async and sync modes are both supported.

MIT License

Downloads
157K
Stars
190

Bot releases are visible (Hide)

FastDepends - 2.4.2 Latest Release

Published by Lancetnik 8 months ago

What's Changed

Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.4.1...2.4.2

FastDepends - 2.4.1

Published by Lancetnik 8 months ago

What's Changed

Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.4.0...2.4.1

FastDepends - 2.4.0

Published by Lancetnik 8 months ago

What's Changed

Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.3.1...0.2.4

FastDepends - 0.2.4b0

Published by Lancetnik 9 months ago

What's Changed

Waiting for FastStream update to release stable version

Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.3.1...0.2.4b0

FastDepends - 2.3.1

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

FastDepends - 2.3.0

Published by Lancetnik 9 months ago

What's Changed

  • Multiple 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
    
  • Support correct Generator annotation
    @inject
     def simple_func(a: str) -> Iterator[int]:
         for _ in range(2):
             yield a
    
     for i in simple_func("1"):
         assert i == 1
    
  • solve async dependencies without subdependencies in parallel tasks
  • solve CustomField with async use_field in parallel
  • build(deps-dev): bump ruff from 0.1.9 to 0.1.11 by @dependabot in https://github.com/Lancetnik/FastDepends/pull/56
  • get rid of protected objects by @VitailOG in https://github.com/Lancetnik/FastDepends/pull/57
  • feat: parallel dependencies resolving by @Lancetnik in https://github.com/Lancetnik/FastDepends/pull/58

New Contributors

Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.8...2.3.0

FastDepends - 2.2.8

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

FastDepends - 2.2.7

Published by Lancetnik 10 months ago

What's Changed

Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.6...2.2.7

FastDepends - 2.2.6

Published by Lancetnik 10 months ago

What's Changed

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

FastDepends - 2.2.5

Published by Lancetnik 10 months ago

What's Changed

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

FastDepends - 2.2.4

Published by Lancetnik 10 months ago

What's Changed

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

FastDepends - 2.2.3

Published by Lancetnik 11 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/Lancetnik/FastDepends/compare/2.2.0...2.2.3

FastDepends - 2.2.0 (2023-09-22) Generators support

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
FastDepends - 2.1.0 (2023-07-17) Args and Kwargs supporting

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

FastDepends - 2.0.1 (2023-06-21) PydanticV2 stable

Published by Lancetnik over 1 year ago

Stable and fulltested PydanticV2 and PydanticV1 both supporting!

FastDepends - 2.0.0b (2023-06-19) PydanticV2

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!

FastDepends - 1.1.0 (2023-04-18)

Published by Lancetnik over 1 year ago

Custom Field is here!

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.

FastDepends - (2023-04-16) INITIAL

Published by Lancetnik over 1 year ago

Inial release

Includes:

  • Depends class with nesting
  • incoming and returning arguments type casting
  • async and sync code supporting

Release 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

Package Rankings
Top 7.98% on Pypi.org
Related Projects