{"id":29101953,"url":"https://github.com/tyilo/golf_indent","last_synced_at":"2025-07-18T05:36:40.138Z","repository":{"id":144985248,"uuid":"38792822","full_name":"tyilo/golf_indent","owner":"tyilo","description":"Utility for indenting a Python 2 file using fewest possible bytes","archived":false,"fork":false,"pushed_at":"2015-07-09T16:54:45.000Z","size":112,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-28T21:09:05.376Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tyilo.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}},"created_at":"2015-07-09T02:45:00.000Z","updated_at":"2015-07-09T02:45:52.000Z","dependencies_parsed_at":"2023-03-31T12:18:06.971Z","dependency_job_id":null,"html_url":"https://github.com/tyilo/golf_indent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tyilo/golf_indent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Fgolf_indent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Fgolf_indent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Fgolf_indent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Fgolf_indent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tyilo","download_url":"https://codeload.github.com/tyilo/golf_indent/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Fgolf_indent/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265705617,"owners_count":23814488,"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-28T21:08:57.180Z","updated_at":"2025-07-18T05:36:40.108Z","avatar_url":"https://github.com/tyilo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# golf_indent\n\nUtility for indenting a Python 2 file using fewest possible bytes.\n\nUsage\n==\n\nYou can provide the file that should be re-indented to `golf_indent` either via stdin or by supplying a filename as the first argument:\n\n```\n$ golf_indent \u003c script.py\n...\n$ golf_indent script.py\n...\n```\n\nExample\n==\n\n`^I` is the tab character and `^D` is ctrl-D.\n\n```\n$ cat \u003e test1.py\n0\n\t1\n\t\t2\n\t\t\t3\n\t\t\t3\n\t\t\t3\n^D\n$ golf_indent test1.py | cat -t\nSaved 8 bytes.\nIndentation used:\n  1: 1 space\n  2: 2 spaces\n  3: 1 tab\n0\n 1\n  2\n^I3\n^I3\n^I3\n$ cat \u003e test2.py\n0\n\t1\n\t\t2\n\t\t2\n\t\t2\n\t\t\t3\n^D\n$ golf_indent test2.py | cat -t\nSaved 4 bytes.\nIndentation used:\n  1: 1 space\n  2: 1 tab\n  3: 1 tab and 1 space\n0\n 1\n^I2\n^I2\n^I2\n^I 3\n```\n\nHow it works\n==\n\nIn Python 2 a tab character counts as 8 spaces for indentation, but is only 1 byte. We can exploit this to reduce the number of bytes needed for indentation in a Python 2 file.\n\nThe optimal way to indent code with 3 or fewer indentation levels is always:\n\n```\n1: space\n2: tab\n```\n\nHowever for code with more indentation levels, it depends on the number of lines for each indentation, which indentation is optimal.\n\nFor instance, when the code has 4 indentation levels, there are two possible optimal indentations:\n\n```\n1: space\n2: 2 spaces\n3: tab\n```\n\nor\n\n```\n1: space\n2: tab\n3: tab + space\n```\n\nThe script tries all possible optimal indentations for a file and outputs the file with that indentation applied. The script also prints the number of bytes saved and the indetation used to stderr.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyilo%2Fgolf_indent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyilo%2Fgolf_indent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyilo%2Fgolf_indent/lists"}