{"id":24839699,"url":"https://github.com/toberocat/pybind11-asyncio-coroutine-example","last_synced_at":"2026-04-16T02:32:04.079Z","repository":{"id":274828237,"uuid":"918949451","full_name":"ToberoCat/pybind11-asyncio-coroutine-example","owner":"ToberoCat","description":"This repository demonstrates a basic integration of C++ coroutines with Python's asyncio using Pybind11. It provides a minimal example of exposing C++ iterators as Python asynchronous iterators, enabling asyncio compatibility without threading.","archived":false,"fork":false,"pushed_at":"2025-01-29T16:53:23.000Z","size":78,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-24T14:51:42.567Z","etag":null,"topics":["asyncio","coroutines","cpp","pybind11","python3"],"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/ToberoCat.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}},"created_at":"2025-01-19T10:07:08.000Z","updated_at":"2025-01-29T16:53:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"4b6d5531-547d-4fb1-8739-8e355a6cc21a","html_url":"https://github.com/ToberoCat/pybind11-asyncio-coroutine-example","commit_stats":null,"previous_names":["toberocat/pybind11-asyncio-coroutine-example"],"tags_count":0,"template":false,"template_full_name":"pybind/cmake_example","purl":"pkg:github/ToberoCat/pybind11-asyncio-coroutine-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToberoCat%2Fpybind11-asyncio-coroutine-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToberoCat%2Fpybind11-asyncio-coroutine-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToberoCat%2Fpybind11-asyncio-coroutine-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToberoCat%2Fpybind11-asyncio-coroutine-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ToberoCat","download_url":"https://codeload.github.com/ToberoCat/pybind11-asyncio-coroutine-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToberoCat%2Fpybind11-asyncio-coroutine-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31868494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"online","status_checked_at":"2026-04-16T02:00:06.042Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["asyncio","coroutines","cpp","pybind11","python3"],"created_at":"2025-01-31T06:48:59.377Z","updated_at":"2026-04-16T02:32:04.071Z","avatar_url":"https://github.com/ToberoCat.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 Asyncio Coroutine Integration with Pybind11\n\n[![Language](https://img.shields.io/badge/language-C%2B%2B%2F%20Python-blue)](https://github.com/)\n\n## 📝 Overview\n\nThis repository provides a minimal yet functional demonstration of integrating **C++20 coroutines** with Python's *\n*asyncio** using **Pybind11**. The goal is to allow calling C++ coroutine functions directly and using them with `await`\nin Python.\n\n**Why this project?**  \nDespite extensive research, no clean and simple way to achieve this was found. This repository serves as a starting\npoint for those looking to bridge C++ coroutines with Python’s asyncio.\n\n## 📂 Project Structure\n\n```\n📦 asyncio-coroutine-pybind11\n├── src/\n│   └── main.cpp       # C++20 coroutine logic with Pybind11 bindings\n├── example/\n│   └── main.py        # Python example showcasing async iterator usage\n├── install.sh         # Script to install dependencies and build extension\n└── README.md          # Documentation\n```\n\n## 🔑 Features\n\n✅ **Bridges C++ coroutines with Python asyncio**  \n✅ **No threading—pure coroutine-based execution**  \n✅ **Provides an async iterator directly callable in Python**  \n✅ **Simple, minimal, and easily extendable**\n\n### 📝 Example\n\n```python\nimport asyncio\nfrom asyncio_example import start_counter\n\nasync def main():\n    task1 = start_counter(10)\n    task2 = start_counter(15)\n    \n    await task1\n    await task2\n\nasyncio.run(main())\n```\n\nThis example demonstrates two concurrent counter coroutines running asynchronously.\n\n## 🛠️ Prerequisites\n\nEnsure you have the following installed:\n\n- Python 3.7+ (with `venv` support)\n- A **C++17+ compiler** (e.g., `g++`, `clang`)\n- **CMake** (for building C++ extension)\n- **Ninja** (optional, for faster builds)\n- **Pybind11** (installed automatically)\n\n## 📥 Clone the Repository\n\n```bash\ngit clone https://github.com/ToberoCat/pybind11-asyncio-coroutine-example.git --recursive\ncd pybind11-asyncio-coroutine-example\n```\n\n## ⚡ Installation \u0026 Usage\n\n### 🔹 Step 1: Set up a Virtual Environment\n\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n```\n\n### 🔹 Step 2: Install \u0026 Build the Extension\n\nRun the provided install script:\n\n```bash\n./install.sh\n```\n\n### 🔹 Step 3: Run the Example\n\n```bash\npython example/main.py\n```\n\n## 📌 Expected Output\n\nRunning `main.py` will create two concurrent counter coroutines. The expected output should resemble:\n\n```\nYielding 0\nYielding 1\nYielding 2\n...\nYielding 10\nYielding 15\n```\n\nIt demonstrates **asynchronous iteration** where Python's `asyncio` can await a C++ coroutine without blocking\nexecution.\n\n## ⚠️ Limitations\n\n🚧 **This is a Proof-of-Concept (PoC).**\n\n- Not optimized for production.\n- Error handling and resource management can be improved.\n- Further refinements and enhancements are encouraged.\n\n## 🤝 Contributing\n\nContributions are welcome! If you find a bug, have suggestions, or want to enhance functionality, feel free to:\n\n1. Fork this repository\n2. Create a feature branch (`git checkout -b feature-name`)\n3. Commit your changes (`git commit -m \"Add new feature\"`)\n4. Push to your branch (`git push origin feature-name`)\n5. Open a **Pull Request**\n\n## 🔗 Resources\n\n- [Pybind11 Documentation](https://pybind11.readthedocs.io/en/stable/)\n- [C++ Coroutines](https://en.cppreference.com/w/cpp/coroutine)\n- [Asyncio in Python](https://docs.python.org/3/library/asyncio.html)\n\nThis repository serves as a **starting point** for integrating **C++20 coroutines** with **Python asyncio** using *\n*Pybind11**. Feel free to explore, modify, and improve it as needed! 🚀  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoberocat%2Fpybind11-asyncio-coroutine-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoberocat%2Fpybind11-asyncio-coroutine-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoberocat%2Fpybind11-asyncio-coroutine-example/lists"}