ets-labs/python-dependency-injector — dự án backend — đang có 4.9k sao GitHub trong nhóm Backend. Dependency injection framework for Python
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
.. image:: https://img.shields.io/github/actions/workflow/status/ets-labs/python-dependency-injector/tests-and-linters.yml?branch=master
:target: https://github.com/ets-labs/python-dependency-injector/actions
:alt: Build Status
.. image:: https://coveralls.io/repos/github/ets-labs/python-dependency-injector/badge.svg?branch=master
:target: https://coveralls.io/github/ets-labs/python-dependency-injector?branch=master
:alt: Coverage Status
What is Dependency Injector?
Dependency Injector is a dependency injection framework for Python.
It helps implement the dependency injection principle.
Key features of the Dependency Injector:
Providers. Provides Factory, Singleton, Callable, Coroutine, Object,
List, Dict, Configuration, Resource, Dependency, and Selector providers
that help assemble your objects.
See Providers <https://python-dependency-injector.ets-labs.org/providers/index.html>_.
Overriding. Can override any provider by another provider on the fly. This helps in testing
and configuring dev/stage environment to replace API clients with stubs etc. See
Provider overriding <https://python-dependency-injector.ets-labs.org/providers/overriding.html>_.
Configuration. Reads configuration from yaml, ini, and json files, pydantic settings,
environment variables, and dictionaries.
See Configuration provider <https://python-dependency-injector.ets-labs.org/providers/configuration.html>_.
Resources. Helps with initialization and configuring of logging, event loop, thread
or process pool, etc. Can be used for per-function execution scope in tandem with wiring.
See Resource provider <https://python-dependency-injector.ets-labs.org/providers/resource.html>_.
Containers. Provides declarative and dynamic containers.
See Containers <https://python-dependency-injector.ets-labs.org/containers/index.html>_.
Wiring. Injects dependencies into functions and methods. Helps integrate with
other frameworks: Django, Flask, Aiohttp, Sanic, FastAPI, etc.
See Wiring <https://python-dependency-injector.ets-labs.org/wiring.html>_.
Asynchronous. Supports asynchronous injections.
See Asynchronous injections <https://python-dependency-injector.ets-labs.org/providers/async.html>_.
Typing. Provides typing stubs, mypy-friendly.
See Typing and mypy <https://python-dependency-injector.ets-labs.org/providers/typing_mypy.html>_.
Performance. Fast. Written in Cython.
Maturity. Mature and production-ready. Well-tested, documented, and supported.
.. code-block:: python
from dependency_injector import containers, providers
from dependency_injector.wiring import Provide, inject
@inject
def main(service: Service = Provide[Container.service]) -> None:
...
if name == "main":
container = Container()
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[name])
main() # <-- dependency is injected automatically
with container.api_client.override(mock.Mock()):
main() # <-- overridden dependency is injected automatically
When you call the main() function the Service dependency is assembled and injected automatically.
When you do testing, you call the container.api_client.override() method to replace the real API
client with a mock. When you call main(), the mock is injected.
You can override any provider with another provider.
It also helps you in a re-configuring project for different environments: replace an API client
with a stub on the dev or stage.
With the Dependency Injector, object assembling is consolidated in a container. Dependency injections are defined explicitly.
This makes it easier to understand and change how an application works.
Visit the docs to know more about the
Dependency injection and inversion of control in Python <https://python-dependency-injector.ets-labs.org/introduction/di_in_python.html>_.
Installation
The package is available on the PyPi_::
pip install dependency-injector
Documentation
The documentation is available here <https://python-dependency-injector.ets-labs.org/>_.
Examples
Choose one of the following:
Application example (single container) <https://python-dependency-injector.ets-labs.org/examples/application-single-container.html>_
Application example (multiple containers) <https://python-dependency-injector.ets-labs.org/examples/application-multiple-containers.html>_
Decoupled packages example (multiple containers) <https://python-dependency-injector.ets-labs.org/examples/decoupled-packages.html>_
Boto3 example <https://python-dependency-injector.ets-labs.org/examples/boto3.html>_
Django example <https://python-dependency-injector.ets-labs.org/examples/django.html>_
Flask example <https://python-dependency-injector.ets-labs.org/examples/flask.html>_
Aiohttp example <https://python-dependency-injector.ets-labs.org/examples/aiohttp.html>_
Sanic example <https://python-dependency-injector.ets-labs.org/examples/sanic.html>_
FastAPI example <https://python-dependency-injector.ets-labs.org/examples/fastapi.html>_
FastAPI + Redis example <https://python-dependency-injector.ets-labs.org/examples/fastapi-redis.html>_
FastAPI + SQLAlchemy example <https://python-dependency-injector.ets-labs.org/examples/fastapi-sqlalchemy.html>_
Tutorials
Choose one of the following:
Flask web application tutorial <https://python-dependency-injector.ets-labs.org/tutorials/flask.html>_
Aiohttp REST API tutorial <https://python-dependency-injector.ets-labs.org/tutorials/aiohttp.html>_
ets-labs/python-dependency-injector thuộc nhóm Backend trên TopGit, cùng 18 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về ets-labs/python-dependency-injector ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/ets-labs/python-dependency-injector là nguồn chính thức.
ets-labs/python-dependency-injector có bao nhiêu sao?
ets-labs/python-dependency-injector có 4.9k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/ets-labs/python-dependency-injector. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
ets-labs/python-dependency-injector có phải mã nguồn mở không?
Có — ets-labs/python-dependency-injector phát hành theo license BSD-3-Clause, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/ets-labs/python-dependency-injector.
ets-labs/python-dependency-injector còn đang phát triển không?
Commit gần nhất trên ets-labs/python-dependency-injector là 2 tháng trước (theo timestamp GitHub). Repo có 351 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
ets-labs/python-dependency-injector dùng license gì?
ets-labs/python-dependency-injector phát hành theo license BSD-3-Clause. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
ets-labs/python-dependency-injector là gì?
ets-labs/python-dependency-injector (ets-labs/python-dependency-injector) là dự án Python trên GitHub. Theo mô tả gốc: Dependency injection framework for Python
ets-labs/python-dependency-injector viết bằng ngôn ngữ gì?
ets-labs/python-dependency-injector chủ yếu viết bằng Python. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về python-dependency-injector?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về python-dependency-injector.