{"id":15374636,"url":"https://github.com/ading2210/python-static","last_synced_at":"2025-10-03T19:56:41.565Z","repository":{"id":207050338,"uuid":"717992132","full_name":"ading2210/python-static","owner":"ading2210","description":"A set of scripts to compile a static Python binary that's only 5.1MB in size, inlcuding the entire standard library.","archived":false,"fork":false,"pushed_at":"2024-06-06T08:52:31.000Z","size":31,"stargazers_count":17,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T14:14:17.458Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ading2210.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}},"created_at":"2023-11-13T06:11:37.000Z","updated_at":"2025-03-16T17:01:25.000Z","dependencies_parsed_at":"2023-11-16T20:04:15.550Z","dependency_job_id":"e5497b1d-3e8e-4807-8c34-fdc1b682b9b7","html_url":"https://github.com/ading2210/python-static","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"83c392c4fac97829f8d190c9414a5fd8f789d9c6"},"previous_names":["ading2210/python-static"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ading2210/python-static","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fpython-static","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fpython-static/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fpython-static/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fpython-static/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ading2210","download_url":"https://codeload.github.com/ading2210/python-static/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fpython-static/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278219771,"owners_count":25950350,"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-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":[],"created_at":"2024-10-01T13:59:13.413Z","updated_at":"2025-10-03T19:56:41.535Z","avatar_url":"https://github.com/ading2210.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Static Python Builder\nThis is a set of scripts to statically compile Python 3.9.18 into a binary that's only 5.1MB in size (after packing with UPX), complete with the entire standard library.\n\nThe purpose of this is to compile the smallest possible Python runtime for use in [shimboot](https://github.com/ading2210/shimboot), but this can be used for other applications as well.\n\n## Explanation:\nStatically compiling the interpreter alone isn't very hard, as you just need to [add a few arguments](https://wiki.python.org/moin/BuildStatically) when building it. However, the resulting binary does not contain the portions of the standard library which are written in pure Python. \n\nTo compile the rest of the standard library, the built in [Freeze](https://wiki.python.org/moin/Freeze) tool is used, which can transpile a Python program into C. A compatible command-line interface is written in `main.py`, which we can run through Freeze. To include the standard library, we can just trick Freeze into thinking they are imported via an unreachable `if` statement containing an `import` of the entire standard library.\n\nThen, Freeze is run, which generates a bunch of C files and a Makefile. Finally, we just run `make` to compile it, producing our static executable. Running it through [UPX](https://upx.github.io/) makes it even smaller, down to the final 5.1MB.\n\n## Usage:\nIf you want to compile this for yourself, you just have to clone this repo, cd into it, and run `build.sh`. This will include the entire standard library, with a few exceptions. Make sure you install [all needed dependencies](https://devguide.python.org/getting-started/setup-building/#install-dependencies) before you run the script.\n\nIf you want to customize which modules are included, edit `patch_main.py`, and add them to the `exclude` list.\n\nIf you have trouble compiling Python in the first place, you may want to exclude the problematic builtin modules in `patch_setup.py`.\n\n## Example:\n```\n$ ./build.sh\n...\nbuild done! check ./main for your executable\nyou can run upx if you want to reduce the size even further\n$ upx ./main --best\n                       Ultimate Packer for eXecutables\n                          Copyright (C) 1996 - 2023\nUPX 4.2.1       Markus Oberhumer, Laszlo Molnar \u0026 John Reiser    Nov 1st 2023\n\n        File size         Ratio      Format      Name\n   --------------------   ------   -----------   -----------\n  15764056 -\u003e   5282888   33.51%   linux/amd64   main                          \n\nPacked 1 file.\n$ ./main --version\nPython 3.9.18, python-static 1.0.0\n$ du -sh ./main\n5.1M    ./main\n$ ldd ./main\n        not a dynamic executable\n```\n\n## Copyright:\nThis repository is licensed under the GNU GPL v3. Unless otherwise indicated, all code has been written by me, [ading2210](https://github.com/ading2210).\n\n### Copyright Notice:\n```\nading2210/python-static: A set of scripts to build a tiny statically linked Python runtime.\nCopyright (C) 2023 ading2210\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see \u003chttps://www.gnu.org/licenses/\u003e.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fading2210%2Fpython-static","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fading2210%2Fpython-static","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fading2210%2Fpython-static/lists"}