{"id":28542703,"url":"https://github.com/pomponchik/contextif","last_synced_at":"2025-07-06T07:31:46.076Z","repository":{"id":206670929,"uuid":"717421580","full_name":"pomponchik/contextif","owner":"pomponchik","description":"Run the function only in a specific context","archived":false,"fork":false,"pushed_at":"2024-01-07T20:29:24.000Z","size":96,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-09T21:07:17.946Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pomponchik.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}},"created_at":"2023-11-11T12:57:49.000Z","updated_at":"2023-11-12T15:59:25.000Z","dependencies_parsed_at":"2023-11-11T14:27:32.006Z","dependency_job_id":"dcefbba3-3931-448c-9376-427fa2922a7f","html_url":"https://github.com/pomponchik/contextif","commit_stats":null,"previous_names":["pomponchik/contextif"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/pomponchik/contextif","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcontextif","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcontextif/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcontextif/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcontextif/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pomponchik","download_url":"https://codeload.github.com/pomponchik/contextif/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcontextif/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263864292,"owners_count":23521766,"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":[],"created_at":"2025-06-09T21:07:19.409Z","updated_at":"2025-07-06T07:31:46.067Z","avatar_url":"https://github.com/pomponchik.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](https://raw.githubusercontent.com/pomponchik/contextif/develop/docs/assets/logo_3.svg)\n\n[![Downloads](https://static.pepy.tech/badge/contextif/month)](https://pepy.tech/project/contextif)\n[![Downloads](https://static.pepy.tech/badge/contextif)](https://pepy.tech/project/contextif)\n[![codecov](https://codecov.io/gh/pomponchik/contextif/graph/badge.svg?token=krgDghlvu7)](https://codecov.io/gh/pomponchik/contextif)\n[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/contextif?branch=main)](https://hitsofcode.com/github/pomponchik/contextif/view?branch=main)\n[![Test-Package](https://github.com/pomponchik/contextif/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/contextif/actions/workflows/tests_and_coverage.yml)\n[![Python versions](https://img.shields.io/pypi/pyversions/contextif.svg)](https://pypi.python.org/pypi/contextif)\n[![PyPI version](https://badge.fury.io/py/contextif.svg)](https://badge.fury.io/py/contextif)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n# contextif: run the function only in a specific context\n\nSometimes we may need to run a function only if it happens in a strictly defined context. In this case, we can use this mini library.\n\nInstall it:\n\n```bash\npip install contextif\n```\n\nAnd use:\n\n```python\nfrom contextif import state\n\nwith state:\n    state(print, 'hello,', 'world!')  # It will be printed.\n\nstate(print, \"it's me, Mario!\")  # It won't.\n```\n\nUsing `state` as a function, you can pass another function and arguments to it there. It will be called only if it happens in a context created also using `state`. The function will not be called out of context.\n\nFor convenience, after the first import of `state`, this variable becomes builtin and you can access it in other modules of your program without importing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpomponchik%2Fcontextif","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpomponchik%2Fcontextif","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpomponchik%2Fcontextif/lists"}