{"id":26247942,"url":"https://github.com/apirogov/ecpz","last_synced_at":"2026-02-27T11:09:32.516Z","repository":{"id":282118623,"uuid":"946332156","full_name":"apirogov/ecpz","owner":"apirogov","description":"Evaluate C++ using Python and Zig","archived":false,"fork":false,"pushed_at":"2025-04-13T14:27:52.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-19T16:46:23.385Z","etag":null,"topics":["clang","cpp","python","zig"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/ecpz/","language":"C","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/apirogov.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-11T01:15:56.000Z","updated_at":"2025-04-13T14:20:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d09d155-703a-4af3-869b-4acd773b6289","html_url":"https://github.com/apirogov/ecpz","commit_stats":null,"previous_names":["apirogov/ecpz"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/apirogov/ecpz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fecpz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fecpz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fecpz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fecpz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apirogov","download_url":"https://codeload.github.com/apirogov/ecpz/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fecpz/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29892064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T09:48:51.284Z","status":"ssl_error","status_checked_at":"2026-02-27T09:48:43.992Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["clang","cpp","python","zig"],"created_at":"2025-03-13T14:16:03.181Z","updated_at":"2026-02-27T11:09:30.597Z","avatar_url":"https://github.com/apirogov.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ecpz - **E**valuate **C**++ using **P**ython and **Z**ig\n\nDo you need to evaluate some simple C++ code from inside your application,\nand it should work cross-platform (Linux, Mac and Windows) without causing a headache?\n\nYou've seen it all, [quine-relay](https://github.com/mame/quine-relay) stopped\nbeing amusing years ago, and you feel the itch for something new?\n\nNo problem, *easy-peasy with `ecpz`!*\n\n----\n\nThis little package combines the ubiquity of Python and ingeniuity of the Zig\ntoolchain to give you the ability to compile C++ snippets without pain.\n\nIf you have a non-trivial project consisting of more than one source file,\nyou should probably configure and build it properly using e.g. [CMake](https://github.com/Kitware/CMake).\n\nIf you need an interactive C++ code execution environment (i.e. a REPL),\ncheck out [cling](https://github.com/root-project/cling).\n\nBut if for some reason you need to produce and execute some ad-hoc throw-away\nC++ snippets as a part of your workflow, `ecpz` might be just what you need!\n\n## Usage\n\nInstall `ecpz` using `pip` or `uv` and check `ecpz --help` for all options.\n\nIn the following, the features of `ecpz` are illustrated by some examples.\n\n### `ecpz run`\n\nCompile and run a single source file provided either as argument or via standard input.\n\nFor example, create `hello.cpp`:\n\n```cpp\n#include \u003cprint\u003e\n\nint main() {\n  std::println(\"Hello world!\");\n}\n```\n\nAnd run it:\n\n```bash\n$ cat hello.cpp | ecpz --clang-arg -std=c++23 run\nHello world!\n```\n\n### `ecpz print`\n\nEvaluates some expressions and pretty-print them using `std::print(ln)` *(note that this automatically implies `-std=c++23`)*.\n\nFor example, create a header `prelude.hpp`:\n\n```cpp\n#include \u003cnumbers\u003e\n#include \u003ctype_traits\u003e\n\ninline double tau() {\n  return 2 * std::numbers::pi;\n}\n```\n\nAnd now run:\n\n```bash\n$ ecpz --prelude prelude.hpp print \"{:.3f} {} {} {}\" \"tau()\" \"[](){ int i=0; ++i; return i; }()\" \"std::is_same_v\u003cint, double\u003e\" \"std::is_same_v\u003cint, int32_t\u003e\"\n6.283 1 false true\n```\n\nYou can set the `ECPZ_PRELUDE` environment variable to the path of your custom\nheader to make it always included by default. Note that as usual, CLI arguments\noverride equivalent environment variables.\n\n### Creating a Quine\n\nUsually, using I/O to let code open itself directly is forbidden and considered bad sportsmanship.\nEverybody agrees that the following things are clear cases of cheating:\n\n* reading a hard-coded string filename\n* using the `argv[0]` trick to reflect back the name of the current file/executable\n* reading the file using some compile- or runtime reflection capabilities of the programming language\n* adding and using a special `quine` command in a custom programming language or environment\n\nWe will do none of these things. Create some source file `FILE` with the following content:\n\n```cpp\n#include \"ecpz/subprocess.hpp\"\nint main(int i, char** a) {\n    using b = std::istreambuf_iterator\u003cchar\u003e; using c = std::string;\n    auto d = [](auto e){ std::ifstream f(e, std::ios::binary); return c(b(f), b()); };\n    std::vector\u003cc\u003e e(i+3, a[i-1]); e[0]=\"ecpz\"; e[1]=\"run\";\n    auto f = i%2 == 0 ? subprocess::run(e).output : d(a[i-1]);\n    subprocess::set_bin(); std::cout\u003c\u003cf;\n}\n```\n\nNow run it with `ecpz run FILE FILE` and convince yourself that we do not cheat in\nsuch despicable and reprehensible ways as the ones listed above!\n\n\u003cdetails\u003e\n  \u003csummary\u003eSpoiler\u003c/summary\u003e\n\n  Nobody ever said that we cannot just...\n\n  * run a C++ source file through `ecpz`,\n    * which uses a Python package,\n      * which provides the `zig` toolchain,\n        * which provides `clang`,\n    * to compile and then run the program, which\n      * runs its arguments through `ecpz`,\n        * compiling and then running the same program, which now finally\n          * prints the file passed to it as the argument\n\n  Or, at least *I* did not get the memo that this is illegal.\n  In that case I apologize for wasting your time.\n\n  But even *if* this is still cheating -\n  isn't cheating in glorious ways not also a form of *art*?\n\n\u003c/details\u003e\n\n## Limitations\n\nThe following issues are fixable, i.e. only a matter of more effort and time:\n\n* currently only synchronous execution is supported, no I/O buffering or streaming\n* currently it is not possible to pipe input data into `ecpz run` to pass it as stdin\n\n## Acknowledgements\n\nThanks to [sheredom](https://github.com/sheredom)\nfor creating [subprocess.h](https://github.com/sheredom/subprocess.h),\nthe only true header-only C(++) subprocess library I could find!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapirogov%2Fecpz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapirogov%2Fecpz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapirogov%2Fecpz/lists"}