A collection of utlities that can be used in other projects.
Project description
from tramp.as_completed import AsCompleted
Tramp
A collection of useful utilities that can be used in any project.
Installation
pip install tramp
Annotations
A wrapper class to simplify accessing information about a type annotation.
As Completed
The AsCompleted type is a wrapper around asyncio.as_completed that adds an async iterator over the results from each task. This simplifies iterating over tasks, eliminating the need to await the next result.
from tramp.as_completed import AsCompleted
...
tasks = [...]
async for result in AsCompleted(*tasks):
...
Additionally it is possible to use AsCompleted in the same way that as_completed operates.
for next_result in AsCompleted(*tasks):
result = await next_result
Containers
A container acts a reference to a changable value.
from tramp import Container
container = Container[int](0)
container.set(1)
print(container.value) # 1
Modules
Helper functions for working with modules
from tramp import modules
from typing import Any
ns: dict[str, Any] = modules.get_module_namespace("some_module")
Optionals
An optional type that can be used with match statements.
from tramp.optionals import Optional
def foo(x: int) -> Optional[int]:
if x > 0:
return Optional.Some(x)
return Optional.Nothing()
result = foo(1)
print(result.value) # 1
result = foo(-1)
print(result.value) # Raises an exception
result = foo(-1)
print(result.value_or(0)) # 0
...
match foo(1):
case Optional.Some(x):
print(x)
case Optional.Nothing():
print("Nothing")
# Output: 1
match foo(-1):
case Optional.Some(x):
print(x)
case Optional.Nothing():
print("Nothing")
# Output: Nothing
Results
A result type that can be used with match statements. Works the same as Optionals with an added error property.
from tramp.results import Result
with Result.build() as result:
result.set(1)
print(result.value) # 1
print(result.error) # None
with Result.build() as result:
raise Execption("Error")
print(result.value) # Raises an exception
print(result.value_or(0)) # 0
print(result.error) # Exception("Error")
Sentinel
A sentinel value that can be used to represent a unique value. Useful for creating NotSet types. Instantiating any
sentinel type will always return the same singleton instance of that type allowing for is checks.
from tramp.sentinels import sentinel
NotSet = sentinel("NotSet")
def foo(x: int | NotSet = NotSet()) -> int:
if x is NotSet():
return 0
return x
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tramp-0.1.12.tar.gz.
File metadata
- Download URL: tramp-0.1.12.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de9e95b3b5a77b070a69520c7dc99f2d1df8c3ef1836fcacdd5c623cde56f44d
|
|
| MD5 |
11015b8ecd4f176f0f878e21e7c573d2
|
|
| BLAKE2b-256 |
f1bca25d56ee98864e507b9ebf4a0f1ded0ff67cea7f98224a9ef23c6ce93801
|
File details
Details for the file tramp-0.1.12-py3-none-any.whl.
File metadata
- Download URL: tramp-0.1.12-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35fde176df48e5f31c5c3822fcb5d5b7e7f61b5162d21ef7ff6c965c778f609c
|
|
| MD5 |
637d9ab7bcb90b542b6adefa610e07db
|
|
| BLAKE2b-256 |
76a6afe672697c4a5fa44e9b0ddbb95027dcfc23256f437dfca91c4ba4d90b31
|