{"id":27260589,"url":"https://github.com/syeysk/sy_py2c","last_synced_at":"2025-09-10T14:35:33.180Z","repository":{"id":37627225,"uuid":"448613659","full_name":"syeysk/sy_py2c","owner":"syeysk","description":"translation Python source into C.","archived":false,"fork":false,"pushed_at":"2024-11-12T09:09:06.000Z","size":322,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T04:44:17.678Z","etag":null,"topics":["c","python","python-c","translation","translator"],"latest_commit_sha":null,"homepage":"https://py2c.ru","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syeysk.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":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-16T16:45:35.000Z","updated_at":"2025-03-03T16:31:30.000Z","dependencies_parsed_at":"2024-11-12T10:19:12.205Z","dependency_job_id":"50f15654-b35a-4e6f-83e4-5c5dd4cdb4fd","html_url":"https://github.com/syeysk/sy_py2c","commit_stats":null,"previous_names":["syeysk/sy_py2c"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syeysk%2Fsy_py2c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syeysk%2Fsy_py2c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syeysk%2Fsy_py2c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syeysk%2Fsy_py2c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syeysk","download_url":"https://codeload.github.com/syeysk/sy_py2c/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345260,"owners_count":21088242,"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":["c","python","python-c","translation","translator"],"created_at":"2025-04-11T04:44:52.273Z","updated_at":"2025-04-11T04:44:52.813Z","avatar_url":"https://github.com/syeysk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Translator from Python into C ([русская версия](README.ru.md))\n\nUse Python-syntax to write a clear C-code for your microcontrollers:\n\n![](docs/this-py2c-translator.png)\n\n[About another variants of Python to C translating](docs/another_translaters.md)\n\n## Examples\n\nUsing is really simple with shortcuts:\n\n```python\nfrom py2c.shortcuts import trans_c\n\nmy_python_code = '''\n    def hello(a: int, b: int = 5) -\u003e string:\n        return 'good' if a + b \u003e 0 else 'not good'\n'''\n\nc_code = trans_c(my_python_code)\nprint(c_code)\n```\n\nWithout shortcuts if you want more control:\n\n```python\nfrom py2c.bytecode_walker import translate\nfrom py2c.translator_cpp import TranslatorC\n\nmy_python_code = '''\n    def hello(a: int, b: int = 5) -\u003e string:\n        return 'good' if a + b \u003e 0 else 'not good'\n'''\n\nwith open('c_code.c') as c_file:\n    translator = TranslatorC(save_to=c_file)\n    translate(translator, my_python_code)\n```\n\n## Install/Uninstall\n\nUse this command to install Py2C:\n```bash\npip install git+https://github.com/syeysk/sy_py2c.git\n```\n\nUse this command to uninstall Py2C:\n```bash\npip uninstall py2c\n```\n\n## Function's and class' description\n\n`py2c.shortcuts.trans_c(source_code, write_to=None)` - translate a python-code into c-code. Arguments:\n- `source_code` - a source python-code like unicode string (type of `str`) or text file object (returning `open` function)\n- `write_to` - a file object to write a result c-code. If `write_to` is `None` (as default), the function will return the c-code as string (type of `str`)\n\n`py2c.TranslatorC(save_to)` - class of python-to-c translator. Contains some methods to translate constructions. Arguments:\n- `save_to` - a file object to write the result c-code\n\n`py2c.translate(translator, source_code: str)` - convert `source_code` into AST, walk it and build c-code. Arguments:\n- `translator` - a instance of translator. For example, `py2c.TranslatorC` or `py2c.TranslatorCpp`\n- `source_code` - a source python-code (type of `str`)\n\n## Command line interface examples\n\nYou can use `py2c` or `python -m py2c` equivalently.\n\nCreate *your_source_code.c* with c-code:\n```bash\npy2c your_source_code.py\n```\n\nCreate *your_output_code.c* with c-code:\n```bash\npy2c your_source_code.py -o your_output_code.c\n```\n\nPrint c-code into console:\n```bash\npy2c your_source_code.py -p\n```\n\n## Roadmap\n\n[Roadmap](ROADMAP.md)\n\n## Support\n\nIf you need help, ask me:\n- https://t.me/py_free_developer\n\nTelegram to get fresh news:\n- https://t.me/syeysk_it\n\n## Links\n\n- [Description of Python nodes](https://greentreesnakes.readthedocs.io/en/latest/nodes.html)\n- [Standard of C](http://www.open-std.org/jtc1/sc22/wg14/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyeysk%2Fsy_py2c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyeysk%2Fsy_py2c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyeysk%2Fsy_py2c/lists"}