{"id":13514695,"url":"https://github.com/zTrix/reprs","last_synced_at":"2025-03-31T03:31:11.303Z","repository":{"id":139975912,"uuid":"55339208","full_name":"zTrix/reprs","owner":"zTrix","description":"Blazing fast repr and eval like string encoding/decoding for python/go!","archived":false,"fork":false,"pushed_at":"2021-05-20T10:06:49.000Z","size":10,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-01T18:37:44.119Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zTrix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2016-04-03T09:34:14.000Z","updated_at":"2023-11-27T19:46:49.000Z","dependencies_parsed_at":"2024-01-31T23:59:26.463Z","dependency_job_id":null,"html_url":"https://github.com/zTrix/reprs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zTrix%2Freprs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zTrix%2Freprs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zTrix%2Freprs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zTrix%2Freprs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zTrix","download_url":"https://codeload.github.com/zTrix/reprs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246413377,"owners_count":20773053,"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":"2024-08-01T05:01:00.501Z","updated_at":"2025-03-31T03:31:10.382Z","avatar_url":"https://github.com/zTrix.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"\n# reprs\n\nreprs provides a safe and blazing-fast implementation for python `repr` and `eval` like string encoding/decoding: `reprs` and `evals`. \n\nBehold!\n\n```python\n\n\u003e\u003e\u003e from reprs import reprs, evals\n\u003e\u003e\u003e a = \"asdf;lkjs\\x00\\n\\xff\\xaafasdf\"\n\n\u003e\u003e\u003e print reprs(a)\nasdf;lkjs\\x00\\n\\xff\\xaafasdf\n\n\u003e\u003e\u003e evals(reprs(a)) == a\nTrue\n```\n\n## speed test\n\n\n```python\nIn [1]: import random\nIn [2]: from reprs import reprs, evals, pyreprs, pyevals\n\nIn [3]: t = ''.join(chr(random.choice(range(256))) for _ in range(1024))\n\nIn [4]: len(t)\nOut[4]: 1024\n\nIn [5]: %timeit reprs(t)\n100000 loops, best of 3: 3.22 µs per loop\n\nIn [6]: %timeit repr(t)\n10000 loops, best of 3: 64.2 µs per loop\n\nIn [7]: %timeit pyreprs(t)\n1000 loops, best of 3: 742 µs per loop\n\nIn [8]: x = reprs(t)\n\nIn [9]: len(x)\nOut[9]: 2983\n\nIn [10]: %timeit evals(x)\n100000 loops, best of 3: 3.68 µs per loop\n\nIn [11]: %timeit pyevals(x)\n1000 loops, best of 3: 941 µs per loop\n\nIn [12]: xx = '\"' + x + '\"'\n\nIn [13]: %timeit eval(xx)\n10000 loops, best of 3: 42.1 µs per loop\n\nIn [14]: evals(x) == t\nOut [14]: True\n\nIn [15]: eval(xx) == t\nOut [15]: True\n```\n\nAs seen above, the speed for `reprs` vs `repr` vs `pyreprs` is roughly `200:10:1`.\n\nThe speed for `evals` vs `eval` for `pyevals` is roughly `280:20:1`.\n\n## Safety\n\n`evals` is implemented using pure string manipulation, don't worried about being pwned(which is a necessary concern when calling `eval`)!\n\n## Interface\n\n### repr related\n\n`reprs` is the c implementation. `pyreprs` is implemented using pure python, which is slow.\n\n - param: `str`, any str input\n - return: `str`, the human readable representation of the input\n\n```python\n\u003e\u003e\u003e from reprs import reprs, evals, pyreprs, pyevals\n\u003e\u003e\u003e import random\n\u003e\u003e\u003e t = ''.join(chr(random.choice(range(256))) for _ in range(20))\n\u003e\u003e\u003e t\n'K\\xffE\\xe7\\xd9\\x93:\\x1f\\x96\\xb5k/=]6\\x8d-`\\xae\\xb4'\n\n\u003e\u003e\u003e reprs(t)\n'K\\\\xffE\\\\xe7\\\\xd9\\\\x93:\\\\x1f\\\\x96\\\\xb5k/=]6\\\\x8d-`\\\\xae\\\\xb4'\n\n\u003e\u003e\u003e print reprs(t)\nK\\xffE\\xe7\\xd9\\x93:\\x1f\\x96\\xb5k/=]6\\x8d-`\\xae\\xb4\n\n\u003e\u003e\u003e reprs(t) == pyreprs(t)\nTrue\n```\n\n\n### evals related\n\n`evals` is the c implementation, `pyevals` is implemented using pure python, which is slow.\n\n`unreprs` is an alias for `evals`, `pyunreprs` is an alias for `pyevals`.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzTrix%2Freprs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FzTrix%2Freprs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzTrix%2Freprs/lists"}