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.3.tar.gz (16.0 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.3-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wrapcco-0.1.3.tar.gz
  • Upload date:
  • Size: 16.0 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.3.tar.gz
Algorithm Hash digest
SHA256 9edb3972e8e2c41f8f7c07fd164ee43975b805e23fd2ae46613b61088efa64e0
MD5 4c8c4130a656a55e8a0a21ae54d538e9
BLAKE2b-256 4043103f0d0fb05da45f221689e8dca55aec6749b6dfc78fe600005f84b2041a

See more details on using hashes here.

Provenance

The following attestation bundles were made for wrapcco-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: wrapcco-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 76719ce6b35fa87795dabe97ec50aa40eed44533a1e7be7ce22185d79c24d997
MD5 085e9463f38f704fc6781adb33ce013b
BLAKE2b-256 5536bcac314418b31c4d5eb39d8c4c8f2abe08922f12b9f1802cb6c3d52e9822

See more details on using hashes here.

Provenance

The following attestation bundles were made for wrapcco-0.1.3-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