Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathbunnyru/python-cpp-extension
Extending Python with simple C++ extension
https://github.com/mathbunnyru/python-cpp-extension
Last synced: 19 days ago
JSON representation
Extending Python with simple C++ extension
- Host: GitHub
- URL: https://github.com/mathbunnyru/python-cpp-extension
- Owner: mathbunnyru
- License: mit
- Created: 2020-06-27T17:20:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-31T15:23:09.000Z (4 months ago)
- Last Synced: 2024-08-01T19:38:55.471Z (4 months ago)
- Language: C++
- Homepage:
- Size: 46.9 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# python-cpp-extension
## Goal
To create a simple example how to extend Python with C++ extensions.
## Requirements
- `python3-dev` or `python3-devel` python development package
- `C++` compiler## Build and install
`python3 setup.py build` will build the `C++` extension.
`python3 setup.py install` will build and install it.
You can use `--user` flag to install to the Python user install directory.
## How to use
First, install the extension. Then you can use it like this:
```python
import cpp_python_extensionprint(cpp_python_extension.sieve_of_eratosthenes(11))
```This will print all the prime numbers from 1 to 11 (inclusive).
## Benchmarking
`python3 -m pytest test_benchmark.py --verbose`
## Files
- `setup.py` - `setuptools` file to easily build and install the extension
- `sieve.h` - header file with declaration of `SieveOfEratosthenes` function
- `sieve.cpp` - implementation file
- `sieve_python_wrapper.cpp` - wrapper around `SieveOfEratosthenes` function to create `cpp_python_extension` module
- `test_benchmark.py` - simple file to benchmark the extension## Credits
[ExtendingPythonTalk](https://github.com/litleleprikon/ExtendingPythonTalk) project