{"id":24016459,"url":"https://github.com/zechcodes/tramp","last_synced_at":"2026-06-11T13:31:28.333Z","repository":{"id":241980323,"uuid":"808367554","full_name":"ZechCodes/Tramp","owner":"ZechCodes","description":"No idea but we have a result type!","archived":false,"fork":false,"pushed_at":"2025-06-08T01:40:41.000Z","size":84,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T02:52:06.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZechCodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-30T23:36:31.000Z","updated_at":"2025-06-08T01:40:45.000Z","dependencies_parsed_at":"2024-05-31T01:35:34.926Z","dependency_job_id":"dfcba8a4-b076-44c7-9e0e-cd1cf73f1b02","html_url":"https://github.com/ZechCodes/Tramp","commit_stats":null,"previous_names":["zechcodes/tramp"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ZechCodes/Tramp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FTramp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FTramp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FTramp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FTramp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZechCodes","download_url":"https://codeload.github.com/ZechCodes/Tramp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FTramp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34201840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-08T08:51:28.547Z","updated_at":"2026-06-11T13:31:28.328Z","avatar_url":"https://github.com/ZechCodes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tramp\n\n[![PyPI](https://img.shields.io/pypi/v/tramp)](https://pypi.org/project/tramp/)\n[![Python](https://img.shields.io/pypi/pyversions/tramp)](https://pypi.org/project/tramp/)\n[![License](https://img.shields.io/pypi/l/tramp)](https://github.com/ZechCodes/Tramp/blob/main/LICENSE)\n[![CI](https://github.com/ZechCodes/Tramp/actions/workflows/ci.yaml/badge.svg)](https://github.com/ZechCodes/Tramp/actions/workflows/ci.yaml)\n\nA collection of useful Python utilities for annotations, async iteration, containers, optionals, protected strings, results, sentinels, and singletons.\n\n## Installation\n\n```\npip install tramp\n```\n\n## Annotations\n\nForward-reference-aware annotation evaluation. On Python \u003c 3.14 it provides a [PEP 649](https://peps.python.org/pep-0649/)-style API for resolving string annotations into `ForwardRef` objects that can be evaluated later. On Python 3.14+ it falls through to the stdlib `annotationlib`.\n\n- `get_annotations(obj, *, format=Format.FORWARDREF)` — evaluate annotations on a class, function, or module\n- `ForwardRef` — a lazy reference that resolves when `.evaluate()` is called\n- `Format` — enum selecting evaluation mode (`FORWARDREF`, `VALUE`, `STRING`)\n\n```python\nfrom tramp.annotations import get_annotations\n\nclass Foo:\n    bar: \"Bar\"\n\nannotations = get_annotations(Foo)  # {'bar': \u003cForwardRef 'Bar'\u003e}\n\nclass Bar:\n    pass\n\nannotations[\"bar\"].evaluate()  # \u003cclass '__main__.Bar'\u003e\n```\n\n## Async Batch Iterator\n\nAn async iterator that pages through batches, yielding items one at a time. Accepts a coroutine that returns an `Iterable`, `AsyncIterable`, or `None` (to signal completion) for each batch index.\n\n- `AsyncBatchIterator[T](get_batch)` — create an iterator from a batch-fetching coroutine\n- `.get(*, limit=None)` — collect all (or up to `limit`) results into a list\n- `.one(*, default=)` — return a single result, or `default` / raise if empty\n\n```python\nfrom tramp.async_batch_iterator import AsyncBatchIterator\n\nasync def get_batch(index: int) -\u003e list[int] | None:\n    if index \u003e 1:\n        return None\n    return list(range(index * 2, (index + 1) * 2))\n\nasync def main():\n    async for item in AsyncBatchIterator(get_batch):\n        print(item)  # 0, 1, 2, 3\n```\n\n## Containers\n\nA mutable reference wrapper. Useful for sharing changeable state across functions or deferring initialization.\n\n- `Container[T](default?)` — create a container, optionally with an initial value\n- `.value` — access the stored value (raises `ValueError` if never set)\n- `.set(value)` — update the stored value\n- `.value_or(default)` — return the value or a fallback if never set\n- `.never_set` — `True` if no value has been assigned\n\n```python\nfrom tramp.containers import Container\n\nconfig = Container[str]()\nprint(config.never_set)      # True\nprint(config.value_or(\"N/A\")) # N/A\n\nconfig.set(\"production\")\nprint(config.value)           # production\n```\n\n## Optionals\n\nA pattern-matchable optional type with `Some` and `Nothing` variants.\n\n- `Optional[V]` — base type (not instantiable directly)\n- `Optional.Some(value)` / `Optional.Nothing()` — construct variants\n- `.value` — unwrap or raise `OptionalHasNoValueException`\n- `.value_or(default)` — unwrap or return a fallback\n- `Optional.wrap(obj)` — convert `None` to `Nothing`, anything else to `Some`\n\n```python\nfrom tramp.optionals import Optional\n\nresult = Optional.wrap(42)\n\nmatch result:\n    case Optional.Some(x):\n        print(f\"Got {x}\")    # Got 42\n    case Optional.Nothing():\n        print(\"Nothing\")\n```\n\n## Protected Strings\n\nStrings that redact themselves when rendered, with selective f-string revelation via `$name` format specs.\n\n- `ProtectedString(value, name=\"\", *, hide_name=False)` — create a redacted string\n- `ProtectedStringBuilder` — built automatically when concatenating protected and plain strings\n- `ProtectedStringFormatError` — raised on invalid format specs\n\n```python\nfrom tramp.protected_strings import ProtectedString\n\ntoken = ProtectedString(\"sk-abc123\", name=\"token\")\nprint(f\"{token}\")             # \u003cRedacted Token\u003e\nprint(f\"{token:$token}\")      # sk-abc123\nprint(f\"{token:***}\")         # ***\nprint(f\"{token:***$token}\")   # sk-abc123\n\nbuilder = ProtectedString(\"user\", name=\"user\") + \":\" + token\nprint(f\"{builder}\")           # \u003cRedacted User\u003e:\u003cRedacted Token\u003e\nprint(f\"{builder:$user,token}\") # user:sk-abc123\n```\n\n## Results\n\nA context-manager-based result type with `Value` and `Error` variants, supporting pattern matching.\n\n- `Result[V]` — base type (not instantiable directly)\n- `Result.build()` — context manager that captures exceptions into `Error`, or a set `.value` into `Value`\n- `.value` — unwrap or raise `ResultWasAnErrorException`\n- `.value_or(default)` — unwrap or return a fallback\n- `.error` — the captured exception, or `None`\n\n```python\nfrom tramp.results import Result\n\nwith Result.build() as result:\n    result.value = 42\n\nmatch result:\n    case Result.Value(v):\n        print(f\"Success: {v}\")  # Success: 42\n    case Result.Error(e):\n        print(f\"Failed: {e}\")\n```\n\n## Sentinels\n\nCreate singleton sentinel types for use as default-value markers or unique tokens.\n\n- `sentinel(name)` — return a new sentinel type whose instances are always the same object\n\n```python\nfrom tramp.sentinels import sentinel\n\nNotSet = sentinel(\"NotSet\")\n\ndef get(key: str, default: int | NotSet = NotSet()) -\u003e int:\n    if default is NotSet():\n        raise KeyError(key)\n    return default\n```\n\n## Singleton\n\nA decorator that makes a class a singleton — all instantiations return the same object.\n\n- `@singleton` — decorate a class to enforce a single instance\n\n```python\nfrom tramp.singleton import singleton\n\n@singleton\nclass Config:\n    def __init__(self):\n        self.debug = False\n\na = Config()\nb = Config()\nassert a is b  # True\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzechcodes%2Ftramp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzechcodes%2Ftramp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzechcodes%2Ftramp/lists"}