tres
Typed resolver (dependency container) for Python
It provides a dependency container for you to use in typed dependency resolution.
That's all. Very type resolution. Much wow.
Inspired by the dependency container in tsyringe, but more Pythonic.
Usage:
from tres import container, InjectionToken
def a(n: int) -> str:
return str(n)
def b(a: int, b: int) -> int:
return a + b
a_token = InjectionToken[Callable[[int], str]]()
b_token = InjectionToken[Callable[[int, int], int]]()
container.register(a_token, a)
container.register(b_token, b)
container.register(b_token, a) # type error
def c(f: Callable[[int], str]):
print(f(1))
c(container[a_token])
c(container[b_token]) # type error
A longer example registering a Protocol
# application logic
from typing import Protocol, Iterable
class OrdersProtocol(Protocol):
def byId(self, id) -> Order:
...
def getLines(self, id) -> Iterable[OrderLine]:
...
OrdersStoreToken = tres.InjectionToken[OrdersProtocol]()
def calculate_total(orders_store: OrdersProtocol, order_id):
order = orders_store.byId(order_id)
lines = orders_store.getLines(order_id)
return sum(line.price for line in lines) + order.shipping
# implementation
from config import URL
from domain import Order, OrderLine
from application import OrdersProtocol, OrdersStoreToken
class OrdersStore(OrdersProtocol):
def __init__(self, url):
self.url = url
def byId(self, id):
return map(Order, requests.get(f'{self.url}/order/{id}').json())
def getLines(self, id):
return map(OrderLine, requests.get(f'{self.url}/order/{id}/lines').json())
tres.container.register(OrdersStoreToken, OrdersStore(URL))
# consumer
from application import calculate_total, OrdersStoreToken
def order_view(order_id):
orders_store = tres.container[OrdersStoreToken]
order = orders_store.byId(order_id)
total = calculate_total(orders_store, order_id)
return f'{order.id} - {order.date}: {total}'
Metadata
Release files for tres 1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tres-1.3.tar.gz | 2.9 kB | Without provenance | Details for tres-1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tres-1.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for tres-1.3-py2.py3-none-any.whl |
Total release size: 7.5 kB
Release files / tres-1.3.tar.gz
| Download URL | tres-1.3.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5cda155d179bd806e48d00cc0592488d8d0ce8dbce0c6c14ee7d2a6fe6fa1973
|
|
BLAKE2b-256 checksum How to use checksums |
ea506dc8b2a0ed6f50146d534ce6ec5a4768ae982205489059f6bcc44d1a638b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.7.5 Darwin/18.7.0
|
Release files / tres-1.3-py2.py3-none-any.whl
| Download URL | tres-1.3-py2.py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
da983bf30dcbfb6ffbfbf7d1e0ecb7a56be5252c769aa7050651bd359825d96e
|
|
BLAKE2b-256 checksum How to use checksums |
353b2b73eac3ff41972b1fcfaf371777fbc8ce125c5613e7216aabc0bbaba148
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.7.5 Darwin/18.7.0
|
Security for tres 1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.