Skip to main content

A Python module to wrap C/C++ code and generate Python extensions.

Project description

wrapc.co logo

Hey there! Welcome to WrapC.co ⚡ – your new shortcut to turbocharged Python extensions! 🚀 Born from the fiery forge of developing Statis.co, our bleeding-edge quantitative finance toolkit, WrapC.co is here to revolutionize how you build Python-C/C++ integrations.

When we first built Statis.co, we brute-forced our way through manual Python-C extensions and Numpy C API integrations. While it worked (and honestly, crushed Numpy-python in speed tests 💨), we quickly hit a wall. Endless boilerplate code, argument parsing gymnastics, and setup file headaches sucked the joy out of development. That's when we thought: "There's gotta be a better way..." ❄️

Enter WrapC.co – the developer experience upgrade you didn't know you needed. We automated the boring bits so you can focus on writing killer C/C++ code instead of wrestling with wrapper setup. Now you can seamlessly expose optimized numerical functions, process Numpy arrays at warp speed, and kiss 80% of that boilerplate junk goodbye 🗑️. Same native performance, 10x the developer zen. 🔮

Installation

Install from PyPi

pip install wrapcco

Install from Source

git clone https://github.com/H3cth0r/wrapc.co
cd wrapc.co
pip install -e .

Direct Install

python3 -m pip install git+https://github.com/H3cth0r/wrapc.co

Documentation

Requirements

  • Python>=3.9.
  • Extensions should be in c++17.
  • MacOs and NixOs support.

Numpy Superpowers 🏗️⚡

Want to crush array operations at C++ speed? Our NumpyArrayRef struct is your new best friend – think of it as a nitro boost for Numpy interop 🚀. Nestled in wrapcco/resources/FunctionWrapper.hpp, this bad boy gives you two killer features right out the gate:

  • array: Your direct line to Numpy's array soul
  • owns_data: Memory management on autopilot ✈️

Check this lightning-round example – we're adding scalars to arrays faster than you can say "zero-copy":

#include <numpy/arrayobject.h>
#include "FunctionWrapper"

NumpyArrayRef addNtoArr(const NumpyArrayRef& a, int nToAdd) {
    // Store array specs ⚙️
    const npy_intp size = a.size();
    double* a_data = a.data<double>();

    // Create output array lightning-fast 🌩️
    npy_intp dims[] = {size};
    PyObject* result_obj = PyArray_SimpleNew(1, dims, NPY_DOUBLE);
    auto* result_arr = reinterpret_cast<PyArrayObject*>(result_obj);
    double* result_data = static_cast<double*>(PyArray_DATA(result_arr));

    // Magic happens here 🎩✨
    for (npy_intp i = 0; i < size; ++i) {
        result_data[i] = a_data[i] + nToAdd;
    }

    return NumpyArrayRef(result_arr);  // Automatic memory VIP treatment 🎟️
}

You can even pass a array as reference and modify the array directly.

void addScalarInPlace(NumpyArrayRef& arr_ref, int scalar) {
    if (arr_ref.dtype() != NPY_DOUBLE) {
        ...
    }
    
    double* data = arr_ref.data<double>();
    npy_intp size = arr_ref.size();
    
    #pragma omp parallel for
    for(npy_intp i = 0; i < size; ++i) {
        data[i] += scalar;
    }
}

Want to compile extensions like an absolute ninja? Grab our header directory with this one-liner:

from wrapcco import get_fw_include
fw_dir = get_fw_include()  # Boom – instant C++ toolkit access 🔧

Examples

For further testing examples, please check this directories:

  • Test Wrapper (test/test_wrapper)
  • Test Wrapper save files (test/test_wrapper_files)
  • Test Wrapper generate library (test/test_wrapper_str_code)
  • Test Wrapper generate library with files (test/test_wrapper_str_code_file)
  • Test Extension and Test Extension save files(test/test_extension)
  • Test Command Line (test/test_command_line)
  • Test Command Line save files (test/test_command_line)

Command Line Usage

python -m wrapcco <library>.hpp --module-name <modulename> --save-script <true/false> --output-path "./"
  • <library>: hpp file containing the library functions.
  • --module-name: name or your output module executable.
  • --save-script: choose if you want to generate the cpp extension file.

Get examples with

wrapcco --help-examples

TODO

  • Add Piping, to streamline functions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wrapcco-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wrapcco-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file wrapcco-0.1.0.tar.gz.

File metadata

  • Download URL: wrapcco-0.1.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for wrapcco-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c05c9122c2635bd009c1727ff39ab7539270b1639d6f4e6a1fb18ecf818daeb3
MD5 6ee3920b012ae0500422569fa8f498bc
BLAKE2b-256 b9cce9c8a3bc38694da745dd425bf4b7c941ae00d6ebc205e1ffa7c3c31a31c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for wrapcco-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on H3cth0r/wrapc.co

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wrapcco-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wrapcco-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for wrapcco-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1d7e300100585363c16374549814d3dbdb94bce137685f0e46af94677f10e2a
MD5 af31c823f03cb9fe654f65325923dea8
BLAKE2b-256 b4481d9e532c9bb707f0ec1ae3a22f819ddf360b84b37e89c17e1f43c0d32ae3

See more details on using hashes here.

Provenance

The following attestation bundles were made for wrapcco-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on H3cth0r/wrapc.co

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page