Best Flask open-source libraries and packages

Wireup

Concise, Powerful, and Type-Safe Python Dependency Injection Library
Updated 1 month ago

Wireup

Dependency Injection Container with a focus on developer experience, type safety and ease of use.

GitHub GitHub Workflow Status (with event) Code Climate maintainability Coverage PyPI - Python Version PyPI - Version

[!TIP] Simplify Dependency injection for Flask using the new Flask integration!

  • Automatically inject dependencies without having to manually call autowire.
  • Expose flask application configuration in the container.

⚡ Key Features

  • Inject Services and Configuration
  • Interfaces / Abstract classes
  • Multiple Containers
  • Static factories
  • Singleton/Transient dependencies
  • Framework Agnostic
  • Simplified usage in Flask and FastApi using the first-party integrations.

📋 Quickstart

Example showing a Database service, a repository and a web view which uses the repository to fetch all posts from a fictional blog db.

1. Register dependencies

from wireup import container

# Optionally wire parameters, they serve as configuration for services. 
# Think of a database url or environment name.
container.params.update(app.config.items())


# Register a class as a service in the container.
@container.register 
class DatabaseService:
    # connection_url will contain the value of the parameter 
    # with the given name in the annotation.
    def __init__(self, connection_url: Annotated[str, Wire(param="db_connection_url")]):
        self.engine = create_engine(connection_url)

        
# Initializer injection is supported for regular classes as well as dataclasses.
@container.register
@dataclass
class PostRepository:
    db: DatabaseService 

    def find_all(self) -> list[Post]:
        return self.db.query...

2. Inject

@app.get("/posts")
@container.autowire 
# Decorate all targets where the library must perform injection, such as views in an Api.
# Services are automatically injected based on annotated type.
# Optional for views when using flask or fastapi integration.
def get_posts(post_repository: PostRepository):
    return post_repository.find_all()

Installation

# Install using poetry:
poetry add wireup

# Install using pip:
pip install wireup

📑 Documentation

For more information check out the documentation

🎮 Demo application

A demo flask application is available at maldoinc/wireup-demo