{"id":15009822,"url":"https://github.com/alessandro308/react_context","last_synced_at":"2025-04-09T17:52:33.912Z","repository":{"id":65604332,"uuid":"585738662","full_name":"alessandro308/react_context","owner":"alessandro308","description":"An API to pass data down in the sub-function inspired by React Context","archived":false,"fork":false,"pushed_at":"2023-01-09T17:58:10.000Z","size":17,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T19:51:34.690Z","etag":null,"topics":["context-api","python","python3","react-context-api"],"latest_commit_sha":null,"homepage":"https://apagiaro.it/react-context-in-python/","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/alessandro308.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}},"created_at":"2023-01-06T00:10:59.000Z","updated_at":"2024-07-17T17:52:33.000Z","dependencies_parsed_at":"2023-02-08T13:10:12.883Z","dependency_job_id":null,"html_url":"https://github.com/alessandro308/react_context","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessandro308%2Freact_context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessandro308%2Freact_context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessandro308%2Freact_context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessandro308%2Freact_context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alessandro308","download_url":"https://codeload.github.com/alessandro308/react_context/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248083346,"owners_count":21045078,"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","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-api","python","python3","react-context-api"],"created_at":"2024-09-24T19:28:48.047Z","updated_at":"2025-04-09T17:52:33.891Z","avatar_url":"https://github.com/alessandro308.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# react_context\n\nAn API to pass data down in the sub-function inspired by React Context\n\n```\npip install react-context\n```\n\nInspired by [this reddit](https://discuss.python.org/t/react-context-api-in-python/5684), here a React Context-like API for Python to pass data down in thesub-function without polluting all the function parameters.\n\nUnder the hood it uses `inspect.stack().frame` to register the element in the context manager. Frames may be available only in CPython. \n\n# Define context values\n\nTo define a context value use `create_context(**kargws)` function\n\n```\n\nwith use_context(something=123):\n    ...\n\n```\n​\n# Retrieve the value somewhere in the code inside of the context\n\nTo retrieve the value, use `get_context(key)` function\n\n# Complete example\n\n```\ndef nested_function():\n    return get_context('something', 'default_value')\n\nwith use_context(something=123):\n    value = nested_function()\n    print(value) # 123\nprint(nested_function()) # 'default_value'\n```\n\n# How to debug the context \n\nTo print in the console where a context has been defined in the stacktrace, replace `get_context` with `debug_context(key, logger=print)`\n\n### For the complete implementation and behaviour, please check the [test file](https://github.com/alessandro308/react_context/blob/main/tests/test_react_context.py).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessandro308%2Freact_context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falessandro308%2Freact_context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessandro308%2Freact_context/lists"}