{"id":13501430,"url":"https://github.com/dflook/python-minifier","last_synced_at":"2025-05-14T11:10:45.551Z","repository":{"id":32640982,"uuid":"137584140","full_name":"dflook/python-minifier","owner":"dflook","description":"Transform Python source code into its most compact representation","archived":false,"fork":false,"pushed_at":"2025-03-11T15:51:59.000Z","size":954,"stargazers_count":632,"open_issues_count":34,"forks_count":45,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-11T04:55:47.959Z","etag":null,"topics":["hacktoberfest","minification","minifier","minify","python","python3"],"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/dflook.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["dflook"]}},"created_at":"2018-06-16T13:53:14.000Z","updated_at":"2025-04-11T00:21:29.000Z","dependencies_parsed_at":"2023-02-12T05:01:41.142Z","dependency_job_id":"f7d4ab91-4270-4647-abd3-96b50f1980f6","html_url":"https://github.com/dflook/python-minifier","commit_stats":{"total_commits":222,"total_committers":5,"mean_commits":44.4,"dds":0.036036036036036,"last_synced_commit":"01af24516ad682482314cfb74aee83521e18dacd"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fpython-minifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fpython-minifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fpython-minifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fpython-minifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dflook","download_url":"https://codeload.github.com/dflook/python-minifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129490,"owners_count":22019628,"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":["hacktoberfest","minification","minifier","minify","python","python3"],"created_at":"2024-07-31T22:01:37.262Z","updated_at":"2025-05-14T11:10:40.533Z","avatar_url":"https://github.com/dflook.png","language":"Python","readme":"# Python Minifier\n\nTransforms Python source code into its most compact representation.\n\n[Try it out!](https://python-minifier.com)\n\npython-minifier currently supports Python 2.7 and Python 3.3 to 3.13. Previous releases supported Python 2.6.\n\n* [PyPI](https://pypi.org/project/python-minifier/)\n* [Documentation](https://dflook.github.io/python-minifier/)\n* [Issues](https://github.com/dflook/python-minifier/issues)\n\nAs an example, the following python source:\n\n```python\ndef handler(event, context):\n    l.info(event)\n    try:\n        i_token = hashlib.new('md5', (event['RequestId'] + event['StackId']).encode()).hexdigest()\n        props = event['ResourceProperties']\n\n        if event['RequestType'] == 'Create':\n            event['PhysicalResourceId'] = 'None'\n            event['PhysicalResourceId'] = create_cert(props, i_token)\n            add_tags(event['PhysicalResourceId'], props)\n            validate(event['PhysicalResourceId'], props)\n\n            if wait_for_issuance(event['PhysicalResourceId'], context):\n                event['Status'] = 'SUCCESS'\n                return send(event)\n            else:\n                return reinvoke(event, context)\n\n        elif event['RequestType'] == 'Delete':\n            if event['PhysicalResourceId'] != 'None':\n                acm.delete_certificate(CertificateArn=event['PhysicalResourceId'])\n            event['Status'] = 'SUCCESS'\n            return send(event)\n\n        elif event['RequestType'] == 'Update':\n\n            if replace_cert(event):\n                event['PhysicalResourceId'] = create_cert(props, i_token)\n                add_tags(event['PhysicalResourceId'], props)\n                validate(event['PhysicalResourceId'], props)\n\n                if not wait_for_issuance(event['PhysicalResourceId'], context):\n                    return reinvoke(event, context)\n            else:\n                if 'Tags' in event['OldResourceProperties']:\n                    acm.remove_tags_from_certificate(CertificateArn=event['PhysicalResourceId'],\n                                                     Tags=event['OldResourceProperties']['Tags'])\n\n                add_tags(event['PhysicalResourceId'], props)\n\n            event['Status'] = 'SUCCESS'\n            return send(event)\n        else:\n            raise RuntimeError('Unknown RequestType')\n\n    except Exception as ex:\n        l.exception('')\n        event['Status'] = 'FAILED'\n        event['Reason'] = str(ex)\n        return send(event)\n```\n\nBecomes:\n\n```python\ndef handler(event,context):\n\tL='OldResourceProperties';K='Tags';J='None';H='SUCCESS';G='RequestType';E='Status';D=context;B='PhysicalResourceId';A=event;l.info(A)\n\ttry:\n\t\tF=hashlib.new('md5',(A['RequestId']+A['StackId']).encode()).hexdigest();C=A['ResourceProperties']\n\t\tif A[G]=='Create':\n\t\t\tA[B]=J;A[B]=create_cert(C,F);add_tags(A[B],C);validate(A[B],C)\n\t\t\tif wait_for_issuance(A[B],D):A[E]=H;return send(A)\n\t\t\telse:return reinvoke(A,D)\n\t\telif A[G]=='Delete':\n\t\t\tif A[B]!=J:acm.delete_certificate(CertificateArn=A[B])\n\t\t\tA[E]=H;return send(A)\n\t\telif A[G]=='Update':\n\t\t\tif replace_cert(A):\n\t\t\t\tA[B]=create_cert(C,F);add_tags(A[B],C);validate(A[B],C)\n\t\t\t\tif not wait_for_issuance(A[B],D):return reinvoke(A,D)\n\t\t\telse:\n\t\t\t\tif K in A[L]:acm.remove_tags_from_certificate(CertificateArn=A[B],Tags=A[L][K])\n\t\t\t\tadd_tags(A[B],C)\n\t\t\tA[E]=H;return send(A)\n\t\telse:raise RuntimeError('Unknown RequestType')\n\texcept Exception as I:l.exception('');A[E]='FAILED';A['Reason']=str(I);return send(A)\n```\n\n## Why?\n\nAWS Cloudformation templates may have AWS lambda function source code embedded in them, but only if the function is less \nthan 4KiB. I wrote this package so I could write python normally and still embed the module in a template.\n\n## Installation\n\nTo install python-minifier use pip:\n\n```bash\n$ pip install python-minifier\n```\n\nNote that python-minifier depends on the python interpreter for parsing source code,\nand outputs source code compatible with the version of the interpreter it is run with.\n\nThis means that if you minify code written for Python 3.11 using python-minifier running with Python 3.12,\nthe minified code may only run with Python 3.12.\n\npython-minifier runs with and can minify code written for Python 2.7 and Python 3.3 to 3.13.\n\n## Usage\n\nTo minify a source file, and write the minified module to stdout:\n\n```bash\n$ pyminify hello.py\n```\n\nThere is also an API. The same example would look like:\n\n```python\nimport python_minifier\n\nwith open('hello.py') as f:\n    print(python_minifier.minify(f.read()))\n```\n\nDocumentation is available at [dflook.github.io/python-minifier/](https://dflook.github.io/python-minifier/)\n\n## License\n\nAvailable under the MIT License. Full text is in the [LICENSE](LICENSE) file.\n\nCopyright (c) 2024 Daniel Flook\n","funding_links":["https://github.com/sponsors/dflook"],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflook%2Fpython-minifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdflook%2Fpython-minifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflook%2Fpython-minifier/lists"}