{"id":23977973,"url":"https://github.com/ertgl/stackholm","last_synced_at":"2026-03-07T04:31:57.375Z","repository":{"id":37096879,"uuid":"479576691","full_name":"ertgl/stackholm","owner":"ertgl","description":"Zero-copy stack-based context data management library.","archived":false,"fork":false,"pushed_at":"2026-02-04T07:11:23.000Z","size":229,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-02-04T19:17:45.332Z","etag":null,"topics":["context-manager","python","stack-based"],"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/ertgl.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-04-09T00:31:48.000Z","updated_at":"2026-02-04T07:11:20.000Z","dependencies_parsed_at":"2023-10-18T17:00:23.361Z","dependency_job_id":"0f1e25b6-98bd-448a-835f-d8d3ef04cb09","html_url":"https://github.com/ertgl/stackholm","commit_stats":{"total_commits":32,"total_committers":2,"mean_commits":16.0,"dds":0.09375,"last_synced_commit":"9826342a2bf1928e229b2cf86c05bbf5c54c7572"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ertgl/stackholm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ertgl%2Fstackholm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ertgl%2Fstackholm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ertgl%2Fstackholm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ertgl%2Fstackholm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ertgl","download_url":"https://codeload.github.com/ertgl/stackholm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ertgl%2Fstackholm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30208025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T03:24:23.086Z","status":"ssl_error","status_checked_at":"2026-03-07T03:23:11.444Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["context-manager","python","stack-based"],"created_at":"2025-01-07T08:15:51.667Z","updated_at":"2026-03-07T04:31:57.358Z","avatar_url":"https://github.com/ertgl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stackholm\n\nA\n[context manager](https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager)\nfor managing scope-specific values using a stack-based approach.\n\n## Table of Contents\n- [Overview](#overview)\n  - [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Single-threaded Environment](#single-threaded-environment)\n  - [Multi-threaded Environment](#multi-threaded-environment)\n  - [Asynchronous Environment](#asynchronous-environment)\n  - [ASGI Environment](#asgi-environment)\n- [Real-world Example](#real-world-example)\n- [License](#license)\n\n## Overview\n\nStackholm is a lightweight Python package for handling context data\nefficiently. It allows storing and retrieving values in a stack-based manner,\nensuring values remain scoped to their respective contexts.\n\n### Features\n\n- Supports single-threaded, multi-threaded, asynchronous, and\n  [ASGI](https://en.wikipedia.org/wiki/Asynchronous_Server_Gateway_Interface)\n  environments.\n- Indexed storage for fast lookups.\n- Zero-copy data sharing across nested contexts.\n- Scopes can be nested within functions or methods, beyond block-level\n  restrictions.\n\n## Installation\n\nThe package is available on [PyPI](https://pypi.org/project/stackholm/), and can\nbe installed using any compatible package manager such as `pip`:\n\n```bash\npip install stackholm\n```\n\n## Usage\n\nStackholm requires a storage class to manage context data. Different storage\nclasses are available for various environments.\n\n### Single-threaded Environment\n\nUse `OptimizedListStorage` for single-threaded applications. This class\nutilizes indexing for efficient lookups.\n\n```python\nimport stackholm\n\n# Create a context class using optimized list storage.\nstorage = stackholm.OptimizedListStorage()\nContext = storage.create_context_class()\n\n# Create a context (checkpoint).\nwith Context():\n    # Set a value in the current context.\n    Context.set_checkpoint_value(\"a\", 1)\n\n    # Output: 1\n    print(Context.get_checkpoint_value(\"a\"))\n\n    # Create another context/checkpoint nested within the current context.\n    with Context() as inner_context:\n        # In this scope, the current context is the `inner_context`.\n\n        # The values from upper contexts are accessible in the current context.\n\n        # Output: 1\n        print(Context.get_checkpoint_value(\"a\"))\n\n        # Mutates the value of `\"a\"`, only for the current context.\n        Context.set_checkpoint_value(\"a\", 2)\n        \n        # Output: 2\n        print(Context.get_checkpoint_value(\"a\"))\n\n    # Back to the previous context.\n    # Output: 1\n    print(Context.get_checkpoint_value(\"a\"))\n\n# The context is closed, and the values are no longer accessible.\n# Raises `stackholm.NoContextIsActive` exception.\nContext.get_checkpoint_value(\"a\")\n```\n\n### Multi-threaded Environment\n\nUse `ThreadLocalStorage` for multi-threaded applications. It extends\n`OptimizedListStorage` and leverages Python’s built-in `threading.local`\nclass to store and retrieve context data.\n\n```python\nimport stackholm\n\nstorage = stackholm.ThreadLocalStorage()\nContext = storage.create_context_class()\n```\n\nFor more information on `threading.local`, refer to the\n[official documentation](https://docs.python.org/3/library/threading.html#thread-local-data).\n\n### Asynchronous Environment\n\nUse `ContextVarStorage` for asynchronous applications. It extends\n`OptimizedListStorage` and leverages the built-in\n`contextvars.ContextVar` class to store and retrieve context data.\n\n```python\nfrom contextvars import ContextVar\n\nimport stackholm\n\n# Create a `ContextVar` instance for storing the context data.\nSTORAGE_STATE_VAR: ContextVar[stackholm.State] = ContextVar(\"STORAGE_STATE_VAR\")\n\n# Pass the `ContextVar` instance to the `ContextVarStorage` constructor.\nstorage = stackholm.ContextVarStorage(STORAGE_STATE_VAR)\nContext = storage.create_context_class()\n```\n\nFor more information on using `ContextVar` with asynchronous applications,\nrefer to the\n[official documentation](https://docs.python.org/3/library/contextvars.html#asyncio-support).\n\n### ASGI Environment\n\nUse `ASGIRefLocalStorage` for ASGI applications. It extends\n`OptimizedListStorage` and utilizes ASGI reference local storage for storing\nand retrieving context data.\n\n```python\nimport stackholm\n\nstorage = stackholm.ASGIRefLocalStorage()\nContext = storage.create_context_class()\n```\n\n## Real-world Example\n\nStackholm is used in [revy](https://github.com/ertgl/revy), a\nre-usable [Django](https://www.djangoproject.com/) application for\nbuilding revision control systems. It tracks data changes and manages\ncontext-related information in a fast and efficient way.\n\n## License\n\nThis project is licensed under the\n[MIT License](https://opensource.org/license/mit).\n\nSee the [LICENSE](LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fertgl%2Fstackholm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fertgl%2Fstackholm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fertgl%2Fstackholm/lists"}