{"id":34034489,"url":"https://github.com/brian-goo/rstypes","last_synced_at":"2025-12-13T19:49:00.992Z","repository":{"id":308320945,"uuid":"982053502","full_name":"brian-goo/rstypes","owner":"brian-goo","description":"Thread-safe async-aware types for Python written in Rust","archived":false,"fork":false,"pushed_at":"2025-08-06T14:49:41.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-29T12:09:54.845Z","etag":null,"topics":["async","asyncio","cache","dict","python","rust","thread","thread-safe-cache","threadsafe"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brian-goo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-05-12T09:57:11.000Z","updated_at":"2025-08-22T07:38:07.000Z","dependencies_parsed_at":"2025-08-05T10:48:57.579Z","dependency_job_id":null,"html_url":"https://github.com/brian-goo/rstypes","commit_stats":null,"previous_names":["brian-goo/rstypes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brian-goo/rstypes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-goo%2Frstypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-goo%2Frstypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-goo%2Frstypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-goo%2Frstypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brian-goo","download_url":"https://codeload.github.com/brian-goo/rstypes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-goo%2Frstypes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27711277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"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":["async","asyncio","cache","dict","python","rust","thread","thread-safe-cache","threadsafe"],"created_at":"2025-12-13T19:48:59.862Z","updated_at":"2025-12-13T19:49:00.987Z","avatar_url":"https://github.com/brian-goo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# rstypes\n\n[![CI](https://img.shields.io/github/actions/workflow/status/brian-goo/rstypes/ci.yml?branch=main\u0026logo=github\u0026label=CI)](https://github.com/brian-goo/rstypes/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)\n[![pypi](https://img.shields.io/pypi/v/rstypes.svg)](https://pypi.org/project/rstypes)\n[![Python versions](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://github.com/brian-goo/rstypes)\n[![PyPI Downloads](https://static.pepy.tech/badge/rstypes)](https://pepy.tech/projects/rstypes)\n\n`rstypes` is a minimal Python package providing **thread-safe**, **async-aware** data types implemented in **Rust**. It is designed for high-performance concurrent and asynchronous programming in Python.\n\nThis library is ideal for building:\n- ✅ **Global or shared dictionaries** across threads or async tasks\n- ✅ **In-memory async-aware caches** with TTL support\n\nInternally, each instance uses a single **mutex**, not per-key locks, which keeps the locking semantics simple and predictable.\n\n## Features\n\n- 🧵 **Thread-safe**: Types that can be safely used across multiple threads.\n- ⚡ **Async-aware**: Compatible with `asyncio` and async/await patterns\n- 🚀 **Rust-powered**: Built with [PyO3](https://github.com/PyO3/pyo3) for blazing-fast native performance\n- 🔐 **Default value support**: Behaves like `collections.defaultdict`\n\n## Installation\n\n```bash\npip install rstypes\n```\n\n## Example Usage\n\n### 🔹 Minimal Example\n\n```python\nimport asyncio\n\nfrom rstypes import RMap\n\nasync def main():\n    d = RMap()\n    await d.set(key=\"hello\", value=123)\n    val = await d.get(\"hello\")\n    assert val == 123\n\n    await d.set(key=7, value=\"answer\")\n    await d.pop(7)\n    val = await d.get(7)\n    assert val is None\n    \nasyncio.run(main())\n```\n\n### 🔹 Async `defaultdict` Behavior\n\n```python\nimport asyncio\n\nfrom rstypes import RMap\n\nasync def main():\n    rlock = RMap(asyncio.Lock) # like defaultdict(asyncio.Lock)\n    \n    async with await rlock.get(\"mykey\"):\n        print(\"Inside an asyncio.Lock\")\n\nasyncio.run(main())\n```\n\n### 🔹 Memory Cache with TTL\n\n```python\nimport asyncio\nfrom typing import NamedTuple\n\nfrom rstypes import RCacheMap\n\nclass Foo(NamedTuple):\n    name: str\n    age: int\n\nasync def main():\n    cache = RCacheMap()\n\n    await cache.set(key=\"hello\", value=123, ttl=1.0)  # 1 second TTL\n    await cache.set(key=\"user\", value=Foo(name=\"Alice\", age=30), ttl=2.0)  # 2 seconds TTL\n\n    await cache.pop(\"hello\")\n    assert await cache.get(\"hello\") is None\n\n    user = await cache.get(\"user\")\n    assert isinstance(user, Foo)\n\n    await asyncio.sleep(2.1)\n    await cache.pop_expired()\n    assert await cache.get(\"user\") is None\n\nasyncio.run(main())\n```\n\n## License\n\n`rstypes` is licensed under the MIT License. See [LICENSE](LICENSE) for more information.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrian-goo%2Frstypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrian-goo%2Frstypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrian-goo%2Frstypes/lists"}