{"id":22922450,"url":"https://github.com/lucafabbian/ipycpp","last_synced_at":"2026-04-15T14:36:17.653Z","repository":{"id":143463348,"uuid":"615772203","full_name":"lucafabbian/ipycpp","owner":"lucafabbian","description":"Simple and hackable jupyter kernel for running c++ (c plus plus) codes inside a python notebook","archived":false,"fork":false,"pushed_at":"2023-03-22T13:55:53.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T14:42:37.440Z","etag":null,"topics":["cplusplus","cpp","jupyter","jupyter-kernel","jupyter-kernels"],"latest_commit_sha":null,"homepage":"","language":"Python","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/lucafabbian.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-03-18T16:28:18.000Z","updated_at":"2023-03-18T19:16:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"2224f982-8f99-4ffd-8efa-f2b711f1fcd5","html_url":"https://github.com/lucafabbian/ipycpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lucafabbian/ipycpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucafabbian%2Fipycpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucafabbian%2Fipycpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucafabbian%2Fipycpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucafabbian%2Fipycpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucafabbian","download_url":"https://codeload.github.com/lucafabbian/ipycpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucafabbian%2Fipycpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31846209,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T13:28:40.153Z","status":"ssl_error","status_checked_at":"2026-04-15T13:28:29.396Z","response_time":63,"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":["cplusplus","cpp","jupyter","jupyter-kernel","jupyter-kernels"],"created_at":"2024-12-14T08:10:20.715Z","updated_at":"2026-04-15T14:36:17.609Z","avatar_url":"https://github.com/lucafabbian.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ipycpp\nSimple and hackable jupyter kernel for running c++ (c plus plus) codes inside a python notebook.\n\nRather than providing a true interactive experience, this kernel would just extract the cpp code from the notebook, compile it on the fly and print the result. It is meant as a drop-in replacement for your main cpp file.\n\nInstall with:\n```\npip install ipycpp\n```\n\nThe package itself is in pure python, and will just call the cpp compiler already installed in your system. Of course, you have to provide a suitable cpp compiler, such as `g++` in order to make it work. Advanced build tools such as `make` should work as well.\n\n## Motivation\nOther packages, such as `xeus-cling` provide a better interactive experience when working with cpp, yet they introduce a lot of magic behind the scene. While developing algorithms with `cpp`, you usually care more about speed and low level control. This package guarantees no overhead - it just transpiles your notebook into a plain `.cpp` file: you may even check the result by yourself. Moreover, since this package is just a ~300lines pure python script, it's way easier to setup.\n\n## Usage\n\n*Note: you may find a complete example here, [example.ipynb](https://github.com/lucafabbian/ipycpp/blob/main/example.ipynb)*\n\nFirst, you have to provide some configuration.\n- `$$ipycpp_file`: this is the location where your code would be extracted\n- `$$ipycpp_build`: this is the command ipycpp should use to compile your code\n- `$$ipycpp_run`: this is the command ipycpp should use to compile your code\n\nCreate a cell with:\n```cpp\n// $$ipycpp_file: src/main.cpp\n// $$ipycpp_build: g++ src/main.cpp -o bin/main\n// $$ipycpp_run: bin/main\n\n\n/* you may also declare global variables and include directives */\n\n#include \u003cstdio.h\u003e\n\nauto hello = \"hello world!\";\n\n```\n\nThen, you may add other cells with some shared functions, for example:\n```cpp\n\nvoid printHelloWorld(){\n\tprintf(\"%s\\n\", hello);\n}\n\n```\n\nFinally, when you want to show some output value, you may declare the usual main function, just remembed to surround it with the special `#ifdef IPYCPP_MAIN` guard or use the \"clevermain\" mode (see below).\n\n```cpp\n#ifdef IPYCPP_MAIN\n#define IPYCPP_MAIN_METHOD\nint main(){\n\tprintHelloWorld();\n}\n#endif\n\n```\n\nKeep in mind that the notebook is stateless. Everything will be recompiled EVERY time. If you change a variable inside a main function and then run another cell, the change will be overwritten.\n\n## CleverMain mode\nIf you wish, you may ask `ipycpp` to automatically recognize your main methods. Use the `// $$ipycpp_clevermain: true` on your first cell instead of writing `#ifdef IPYCPP_MAIN` every time.\n\nFor example:\n\n```cpp\n// $$ipycpp_file: src/main.cpp\n// $$ipycpp_build: g++ src/main.cpp -o bin/main\n// $$ipycpp_run: bin/main\n// $$ipycpp_clevermain: true\n\n#include \u003cstdio.h\u003e\n\nauto hello = \"hello world!\";\n\n\nint main(){\n  \tprintf(\"%s\\n\", hello);\n}\n```\n```cpp\n// another cell\nint main(){\n  \tprintf(\"another cell, %s\\n\", hello);\n}\n```\n\nThis works 99% of the times, but may incur into issues if you are doing some weird preprocessor magic (`ipycpp` has no way to resolve in advance your `#define` directives).\n\n## Special formatting\nYou may provide non-textual data to the notebook, such as html or images, by printing some special tags. This feature is enabled by default, and let you create interactive notebooks.\n\n### disable\nTo disable any kind of special data for the rest of the cell, just print `$$$ipycppr_disable_special_output$$$` at the beginning of your main.\n\nFor example:\n```cpp\nprintf(\"$$$ipycppr_disable_special_output$$$\\n\");\n```\nIn this way, you will be sure that any further output will be printed \"as is\".\n\n### images or other files\nYou may display an image (or another kind of file) by printing the special tag `$$$ipycppr_file$$$` followed by the image path. ipycpp will guess the kind of file from the extension. For example:\n```cpp\nprintf(\"$$$ipycppr_file$$$%s\\n\", \"myfolder/myimage.png\");\n```\n\n### html\nMark html regions with `$$$ipycppr_html_start$$$` and `$$$ipycppr_html_end$$$` (newline required). You may also add some javascript logic to create interactive widgets.\n\nBasic example:\n```cpp\nprintf(\"$$$ipycppr_html_start$$$\\n%s\\n$$$ipycppr_html_end$$$\\n\", \"\u003cb\u003esome bold text\u003c/b\u003e\");\n```\n\nAdvanced example (this will create an interactive widget using the [PetiteVue library](https://github.com/vuejs/petite-vue); the widget will display a number and two buttons to increment or decrement it):\n```cpp\nauto html = R\"\"\"\"(\n\n\u003cdiv class=\"widgetcontainer\"\u003e\n  \u003cdiv class=\"widget\" v-scope=\"{ count: 0 }\"\u003e\n    \u003cbutton @click=\"count--\"\u003e-\u003c/button\u003e\n    {{ count }}\n    \u003cbutton @click=\"count++\"\u003e+\u003c/button\u003e\n  \u003c/div\u003e\n\n  \u003cscript\u003e\n  if(!window.INSTALL_PETITE_VUE){\n    let resolve = null;\n    window.INSTALL_PETITE_VUE = new Promise(r =\u003e resolve = r);\n    function loadPetiteVue(){\n      var script = document.createElement('script');\n      script.src = 'https://unpkg.com/petite-vue';\n      script.onload = resolve;\n      script.onerror = () =\u003e setTimeout(loadPetiteVue, 1000)\n      document.head.appendChild(script);\n    }\n    loadPetiteVue()\n  }\n\n  {\n    // get current element right now, and mount it as soon as petite-vue is loaded\n    let element = document.currentScript.previousElementSibling;\n    window.INSTALL_PETITE_VUE.then(() =\u003e PetiteVue.createApp().mount(element));\n  }\n\n  \u003c/script\u003e\n\u003c/div\u003e\n)\"\"\"\";\n\n#ifdef IPYCPP_MAIN\n#define IPYCPP_MAIN_METHOD\nint main(){\n\tprintf(\"$$$ipycppr_html_start$$$\\n%s\\n$$$ipycppr_html_end$$$\\n\", html);\n}\n#endif\n```\n\n\n## Authors and license\n\nMain author: Luca Fabbian \u003cluca.fabbian.1999@gmail.com\u003e\n\nFreely distributed under MIT license.\n\nFeel free to open a github issue to report bugs or submit feature requests!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucafabbian%2Fipycpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucafabbian%2Fipycpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucafabbian%2Fipycpp/lists"}