<div align="center">
# 🚀 Pyrex
**Seamless inline Rust, C, and C++ execution inside Python — with enterprise-grade safety, performance, and simplicity**
[](https://pypi.org/project/pyrex3/)
*Write native Rust, C, and C++ code inline with Python. Automatically compiled, cached, and sandboxed — ready for production.*
</div>
---
## ✨ Features
- 🦀 **Rust-first** – Full Rust support with automatic compilation
- ⚡ **C & C++ support** – Modern C/C++ with type-safe bridging
- 🔒 **Enterprise security** – Sandboxed execution, validation, and resource limits
- 🚀 **Smart caching** – Compiles once, executes instantly on repeat
- 🎯 **Type-safe** – Automatic Python ↔ native type conversion
- 📊 **Detailed errors** – Rich compile/runtime diagnostics with context
- 🔧 **Zero config** – Works out of the box, no setup needed
---
## 🛠️ Installation
```bash
pip install pyrex3
```
**Requirements:**
You’ll need `rustc`, `gcc`/`clang`, and `g++`/`clang++` installed.
---
## 🚀 Quick Start
### Rust Example
```python
from pyrex.languages.rust import rust
result = rust.execute("""
let numbers = vec![1, 2, 3, 4, 5];
let sum: i32 = numbers.iter().sum();
println!("Sum: {}", sum);
""")
print(result) # "Sum: 15"
```
### C Example
```python
from pyrex import c
result = c.execute("""
int result = x * y + z;
printf("Result: %d\\n", result);
""", {"x": 10, "y": 20, "z": 5}, fast=True)
print(result) # "Result: 205"
```
### C++ Example
```python
from pyrex import cpp
result = cpp.execute("""
std::vector<int> data = numbers;
std::sort(data.begin(), data.end());
std::cout << "Sorted: ";
for (int n : data) std::cout << n << " ";
std::cout << std::endl;
""", variables={"numbers": [64, 34, 25, 12, 22, 11, 90]})
print(result)
```
---
## 📚 Advanced Usage
### Custom Compiler Settings
```python
from pyrex.languages.rust import RustCompiler
from pyrex.core.base import CompilerConfig
compiler = RustCompiler(
config=CompilerConfig(
compile_flags=["-O", "--edition", "2021"],
cache_dir="/tmp/pyrex_cache",
enable_security=True
)
)
result = compiler.execute("""
let result = (0..1_000_000).sum::<i64>();
println!("Sum: {}", result);
""")
print(result)
```
### Error Handling
```python
from pyrex.exceptions import PyrexCompileError, PyrexRuntimeError
try:
rust.execute("let x = ;") # Invalid syntax
except PyrexCompileError as e:
print(f"Compilation failed at line {e.line_number}: {e.message}")
print(f"Snippet:\n{e.code_snippet}")
```
---
## 🔒 Security
Pyrex enforces **enterprise-grade safety** out of the box:
- Static analysis for dangerous patterns
- Sandboxed execution in temp directories
- Input sanitization & type validation
- Memory, CPU, and timeout limits
---
## 🎯 Type Mapping
| Python Type | Rust | C | C++ |
|--------------|-------------|-------------|----------------------|
| `bool` | `bool` | `bool` | `bool` |
| `int` | `i64` | `long long` | `long long` |
| `float` | `f64` | `double` | `double` |
| `str` | `String` | `char*` | `std::string` |
| `list[int]` | `Vec<i64>` | `int[]` | `std::vector<int>` |
---
## ⚡ Performance
- **First run:** Compiles & caches the binary
- **Next runs:** Executes instantly (10–100× faster)
- **Smart invalidation:** Cache refreshes automatically when code or variables change
---
## 📖 API Reference
### `execute(code, variables={"key": "value"}, timeout=30.0, force_recompile=False, fast=True)`
**Parameters:**
- `code` *(str)* – Source code to compile and run
- `variables` *(dict, optional)* – Injected variables
- `timeout` *(float, default=30s)* – Max runtime
- `force_recompile` *(bool)* – Ignore cache, force rebuild
- `fast` *(bool)* – Skips few checks to get faster compilation
**Returns:**
- Execution output as `str`
**Raises:**
- `PyrexCompileError` – Compilation failed
- `PyrexRuntimeError` – Runtime error
- `PyrexTypeError` – Type conversion issue
- `PyrexSecurityError` – Security violation
---
## 🤝 Contributing
1. Fork this repository
2. Create a feature branch: `git checkout -b feature/my-feature`
3. Make your changes
4. Submit a pull request 🎉
---
## 📄 License
Licensed under the MIT License. See the [LICENSE](LICENSE) file.
---
## 🙏 Acknowledgments
- Built with ❤️ by Luciano Correia
- Inspired by the need for **frictionless multi-language execution**
- Thanks to all contributors and early testers
Raw data
{
"_id": null,
"home_page": null,
"name": "pyrex3",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "kendroooo <sudo@shiro.lol>",
"keywords": "compiler, rust, c, cpp, execution, fast, security, multi-language, code-execution, performance",
"author": null,
"author_email": "kendroooo <sudo@shiro.lol>",
"download_url": "https://files.pythonhosted.org/packages/d9/70/2778d0c9a3a84ce677486305a68edbe5ea769fc3ecc2cef85841448b0fd9/pyrex3-1.0.3.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n\n# \ud83d\ude80 Pyrex\n\n**Seamless inline Rust, C, and C++ execution inside Python \u2014 with enterprise-grade safety, performance, and simplicity**\n\n[](https://pypi.org/project/pyrex3/)\n\n*Write native Rust, C, and C++ code inline with Python. Automatically compiled, cached, and sandboxed \u2014 ready for production.*\n\n</div>\n\n---\n\n## \u2728 Features\n\n- \ud83e\udd80 **Rust-first** \u2013 Full Rust support with automatic compilation \n- \u26a1 **C & C++ support** \u2013 Modern C/C++ with type-safe bridging \n- \ud83d\udd12 **Enterprise security** \u2013 Sandboxed execution, validation, and resource limits \n- \ud83d\ude80 **Smart caching** \u2013 Compiles once, executes instantly on repeat \n- \ud83c\udfaf **Type-safe** \u2013 Automatic Python \u2194 native type conversion \n- \ud83d\udcca **Detailed errors** \u2013 Rich compile/runtime diagnostics with context \n- \ud83d\udd27 **Zero config** \u2013 Works out of the box, no setup needed \n\n---\n\n## \ud83d\udee0\ufe0f Installation\n\n```bash\npip install pyrex3\n```\n\n**Requirements:** \nYou\u2019ll need `rustc`, `gcc`/`clang`, and `g++`/`clang++` installed.\n\n---\n\n## \ud83d\ude80 Quick Start\n\n### Rust Example\n```python\nfrom pyrex.languages.rust import rust\n\nresult = rust.execute(\"\"\"\n let numbers = vec![1, 2, 3, 4, 5];\n let sum: i32 = numbers.iter().sum();\n println!(\"Sum: {}\", sum);\n\"\"\")\nprint(result) # \"Sum: 15\"\n```\n\n### C Example\n```python\nfrom pyrex import c\n\nresult = c.execute(\"\"\"\n int result = x * y + z;\n printf(\"Result: %d\\\\n\", result);\n\"\"\", {\"x\": 10, \"y\": 20, \"z\": 5}, fast=True)\n\nprint(result) # \"Result: 205\"\n```\n\n### C++ Example\n```python\nfrom pyrex import cpp\n\nresult = cpp.execute(\"\"\"\n std::vector<int> data = numbers;\n std::sort(data.begin(), data.end());\n\n std::cout << \"Sorted: \";\n for (int n : data) std::cout << n << \" \";\n std::cout << std::endl;\n\"\"\", variables={\"numbers\": [64, 34, 25, 12, 22, 11, 90]})\n\nprint(result)\n```\n\n---\n\n## \ud83d\udcda Advanced Usage\n\n### Custom Compiler Settings\n```python\nfrom pyrex.languages.rust import RustCompiler\nfrom pyrex.core.base import CompilerConfig\n\n\ncompiler = RustCompiler(\n config=CompilerConfig(\n compile_flags=[\"-O\", \"--edition\", \"2021\"],\n cache_dir=\"/tmp/pyrex_cache\",\n enable_security=True\n )\n)\n\n\nresult = compiler.execute(\"\"\"\n let result = (0..1_000_000).sum::<i64>();\n println!(\"Sum: {}\", result);\n\"\"\")\n\nprint(result)\n\n```\n\n### Error Handling\n```python\nfrom pyrex.exceptions import PyrexCompileError, PyrexRuntimeError\n\ntry:\n rust.execute(\"let x = ;\") # Invalid syntax\nexcept PyrexCompileError as e:\n print(f\"Compilation failed at line {e.line_number}: {e.message}\")\n print(f\"Snippet:\\n{e.code_snippet}\")\n```\n\n---\n\n## \ud83d\udd12 Security\n\nPyrex enforces **enterprise-grade safety** out of the box:\n- Static analysis for dangerous patterns \n- Sandboxed execution in temp directories \n- Input sanitization & type validation \n- Memory, CPU, and timeout limits \n\n---\n\n## \ud83c\udfaf Type Mapping\n\n| Python Type | Rust | C | C++ |\n|--------------|-------------|-------------|----------------------|\n| `bool` | `bool` | `bool` | `bool` |\n| `int` | `i64` | `long long` | `long long` |\n| `float` | `f64` | `double` | `double` |\n| `str` | `String` | `char*` | `std::string` |\n| `list[int]` | `Vec<i64>` | `int[]` | `std::vector<int>` |\n\n---\n\n## \u26a1 Performance\n\n- **First run:** Compiles & caches the binary \n- **Next runs:** Executes instantly (10\u2013100\u00d7 faster) \n- **Smart invalidation:** Cache refreshes automatically when code or variables change \n\n---\n\n## \ud83d\udcd6 API Reference\n\n### `execute(code, variables={\"key\": \"value\"}, timeout=30.0, force_recompile=False, fast=True)`\n\n**Parameters:** \n- `code` *(str)* \u2013 Source code to compile and run \n- `variables` *(dict, optional)* \u2013 Injected variables \n- `timeout` *(float, default=30s)* \u2013 Max runtime \n- `force_recompile` *(bool)* \u2013 Ignore cache, force rebuild \n- `fast` *(bool)* \u2013 Skips few checks to get faster compilation\n\n**Returns:** \n- Execution output as `str`\n\n**Raises:** \n- `PyrexCompileError` \u2013 Compilation failed \n- `PyrexRuntimeError` \u2013 Runtime error \n- `PyrexTypeError` \u2013 Type conversion issue \n- `PyrexSecurityError` \u2013 Security violation \n\n---\n\n## \ud83e\udd1d Contributing\n\n1. Fork this repository \n2. Create a feature branch: `git checkout -b feature/my-feature`\n3. Make your changes \n4. Submit a pull request \ud83c\udf89 \n\n---\n\n## \ud83d\udcc4 License\n\nLicensed under the MIT License. See the [LICENSE](LICENSE) file.\n\n---\n\n## \ud83d\ude4f Acknowledgments\n\n- Built with \u2764\ufe0f by Luciano Correia \n- Inspired by the need for **frictionless multi-language execution** \n- Thanks to all contributors and early testers \n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Lightning-fast multi-language code execution engine with security-first design",
"version": "1.0.3",
"project_urls": {
"Discussions": "https://github.com/kendroooo/pyrex/discussions",
"Homepage": "https://github.com/kendroooo/pyrex",
"Repository": "https://github.com/kendroooo/pyrex.git"
},
"split_keywords": [
"compiler",
" rust",
" c",
" cpp",
" execution",
" fast",
" security",
" multi-language",
" code-execution",
" performance"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ccb77a702195717ba2d1b750ed1a830a65103f3ad1f83d40149564f30c2acc30",
"md5": "337914913c307ef8f2aa39a5498efd5e",
"sha256": "28c7fd08c71c06d3ddbf0d1c2be37506654849fb15e3c35c701b51b4ac6cbc08"
},
"downloads": -1,
"filename": "pyrex3-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "337914913c307ef8f2aa39a5498efd5e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 45520,
"upload_time": "2025-09-10T08:53:20",
"upload_time_iso_8601": "2025-09-10T08:53:20.134862Z",
"url": "https://files.pythonhosted.org/packages/cc/b7/7a702195717ba2d1b750ed1a830a65103f3ad1f83d40149564f30c2acc30/pyrex3-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d9702778d0c9a3a84ce677486305a68edbe5ea769fc3ecc2cef85841448b0fd9",
"md5": "fc79130d2d6d2cc564eb984758fed8a1",
"sha256": "7ee1b8b252ea2d9359fe10624fd78d373da05c1849a4c37412377c6dc535d8ae"
},
"downloads": -1,
"filename": "pyrex3-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "fc79130d2d6d2cc564eb984758fed8a1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 40215,
"upload_time": "2025-09-10T08:53:29",
"upload_time_iso_8601": "2025-09-10T08:53:29.189222Z",
"url": "https://files.pythonhosted.org/packages/d9/70/2778d0c9a3a84ce677486305a68edbe5ea769fc3ecc2cef85841448b0fd9/pyrex3-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-10 08:53:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kendroooo",
"github_project": "pyrex",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyrex3"
}