Skip to main content

A collection of utlities that can be used in other projects.

Project description

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tramp-0.1.11.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tramp-0.1.11-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file tramp-0.1.11.tar.gz.

File metadata

  • Download URL: tramp-0.1.11.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.8.0-1014-azure

File hashes

Hashes for tramp-0.1.11.tar.gz
Algorithm Hash digest
SHA256 4f2309f11c3b2d6394c435ee9f9d4487ab0fd76cd8230f18fedf85a00d79aeff
MD5 a9768e0ddb8f6143761bd7ffb2522ed9
BLAKE2b-256 9ed2e93120495abd0b570adba8908029e741ff07e200940713d28b75e18383b7

See more details on using hashes here.

File details

Details for the file tramp-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: tramp-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.8.0-1014-azure

File hashes

Hashes for tramp-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 dd19f5bd05fc9f74d81bd48c1071418607b857393c722eb0570d66675f432663
MD5 48c636a308bb80c4feeda8ef3f779e40
BLAKE2b-256 a5605992ba9162282aca5725d87b45f9db436d4b416f5a1e05658f474aba8c26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page