{"id":22006049,"url":"https://github.com/flipbit03/main","last_synced_at":"2026-01-16T10:57:44.283Z","repository":{"id":262922819,"uuid":"888791113","full_name":"flipbit03/main","owner":"flipbit03","description":"For those that think `if __name__ = \"__main__\"` is ugly","archived":false,"fork":false,"pushed_at":"2024-12-07T20:46:37.000Z","size":19,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-14T07:59:03.556Z","etag":null,"topics":["python3","utils"],"latest_commit_sha":null,"homepage":"","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/flipbit03.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}},"created_at":"2024-11-15T02:29:29.000Z","updated_at":"2025-01-01T14:05:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"805986dc-4e7c-48d5-8aa0-98edccb7e1ec","html_url":"https://github.com/flipbit03/main","commit_stats":null,"previous_names":["flipbit03/main"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/flipbit03/main","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipbit03%2Fmain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipbit03%2Fmain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipbit03%2Fmain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipbit03%2Fmain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flipbit03","download_url":"https://codeload.github.com/flipbit03/main/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipbit03%2Fmain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266631351,"owners_count":23959419,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["python3","utils"],"created_at":"2024-11-30T01:02:08.040Z","updated_at":"2026-01-16T10:57:44.266Z","avatar_url":"https://github.com/flipbit03.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# @python_main\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/python-main)](https://pypi.org/project/python-main/)\n[![PyPI - Version](https://img.shields.io/pypi/v/python-main)](https://pypi.org/project/python-main/)\n\n\n`@python_main` is a decorator which:\n- Automatically calls the function(s) tagged with it, if the current module is being **executed as a script**.\n- Does nothing if the current module is being **imported**.\n\nIt is, essentially, equivalent to the `if __name__ == \"__main__\":` construct, but as a decorator.\n\nThat's all it does.\n\n### Installation\n\n```bash\npip install python-main # or\npoetry add python-main # ...\n```\n\n### Usage\n\n```python\nfrom python_main import python_main\n\nA = 10\nB = 20\n\n@python_main\ndef do_print():\n    \"\"\"This will run if this module is executed.\"\"\"\n    print(A + B)\n```\n\nYou can also tag multiple functions with `@python_main` and they will all run if the module is executed, in the order they are defined.\n\n```python\nfrom python_main import python_main\n\nA = 10\nB = 20\nC = 0\n\n@python_main\ndef add_a_to_c():\n    global C\n    C += A\n\n# ... other functions/ definitions ...\n\n@python_main\ndef add_b_to_c():\n    global C\n    C += B\n\n# At this point:\n# - C will be 30 if this module is executed as a script.\n# - C will be untouched if this module is imported.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipbit03%2Fmain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflipbit03%2Fmain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipbit03%2Fmain/lists"}