Fastapi Injectable

Fastapi Injectable

Visit Site

Here is a rewritten version of the text in a more readable and concise format:

Introduction

fastapi-injectable is a Python library that provides a simple way to manage dependencies in FastAPI applications. It allows you to define dependencies as functions or classes, which can be used throughout your application.

Key Features

  • Dependency Injection: Define dependencies as functions or classes, which can be injected into other components.
  • Fresh Dependencies per Message: Each message gets a fresh set of dependencies through _init_as_consumer().
  • Proper Resource Management: Dependencies with cleanup needs (like database connections) are properly handled.
  • Graceful Shutdown: setup_graceful_shutdown() ensures resources are cleaned up on program termination.

Real-world Examples

You can find real-world examples of using fastapi-injectable in various scenarios, including processing messages by background worker and resource cleanup. These examples demonstrate how to handle complex dependency trees, resource management, and mixing sync/async code.

Contributing

Contributions are welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, fastapi-injectable is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

  1. This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.
  2. Thanks to @barapa's initiation, his work inspires me to create this project.

Related Issue & Discussion

You can find related issues and discussions on the FastAPI GitHub page.