Skip to main content

C++ DSP Extensions for Python.

Project description

python-cxx

uv Python Version from PEP 621 TOML PyPI - Implementation Build PyPI - Wheel GitHub License

C/C++ DSP Extensions for Python.

Building the foundation for a fast, reliable, easy-to-use signal processing toolset.

This package is about real-world utility, learning, and most of all fun!

Installation & Usage

pip install python-cxx

Once the package has been installed you can run the example with

python-cxx-example

If successful, you should see something like this

---------------------------------------------------------
Hello from python_cxx!!!
A C++ compiled extension that can operate in Python.
For example, given a list [1, 2, 3]...one can use:
---------------------------------------------------------
* Typecasting to e.g. square: python_cxx.IntVector([1, 4, 9])
* Binding to e.g. double: python_cxx.IntVector([2, 4, 6])
* Or wrap an operation like decrement: [0, 1, 2]!
Executing a C++ class method on [1. 1. 1. 1. 1.] gives:
Exponential average: [0.9     0.99    0.999   0.9999  0.99999]

Benchmark Results
-----------------
* Ran 100 trials 5 times.
* Time of one independent trial: 2.92 msec
* Best time of subsequent trials: 2.7 msec
* Worst time of subsequent trials: 2.92 msec
* Best speed: 152 Mitems / sec
* Worst speed: 140 Mitems / sec

Experiment with the example script (python-cxx/example.py), use with the interpreter, or get the source and add your own features!

>>> import numpy as np
>>> from python_cxx import decrement_it
>>> x = [1, 2, 3]
>>> decrement_it(x)
[0, 1, 2]

Source Installation & Development

Install

Get uv

curl -LsSf https://astral.sh/uv/install.sh | sh

Get the code and go to the project directory

git clone https://github.com/hunterdsp/python-cxx.git && cd python-cxx

Synchronize dependencies and install

uv sync

Develop

  • Edit the code
  • Add testing
  • Commit!
  • Synchronize: uv sync
  • Run scripts e.g.: uv run --no-editable python-cxx-example
  • Ensure ALL tests pass: uvx pytest
  • Repeat until you make it here with no failures
  • Submit a pull-request

... more coming soon ... Have Fun!!!

Debugging

Create a debug environment and install ALL dependencies adding meson-python

uv venv .venv.debug --clear
. .venv.debug/bin/activate
uv pip install . meson-python

Build the extension with debug symbols

uv pip install --editable . --no-build-isolation \
    -Csetup-args=-Dbuildtype=debug \
    -Cbuild-dir=build-dbg

Attach to the example with gdb and set a breakpoint on the step method

gdb --args python3.12 -c "from python_cxx_example import main; main()"
break step
run

You should see the debugger stop on the first call to step() like so

[New Thread 0x7fffcddf26c0 (LWP 612534)]
[New Thread 0x7fffcd5f16c0 (LWP 612539)]
Downloading separate debug info for ...

---------------------------------------------------------
Hello from python_cxx!!!
A C++ compiled extension that can operate in Python.
For example, given a list [1, 2, 3]...one can use:
---------------------------------------------------------
* Typecasting to e.g. square: python_cxx.IntVector([1, 4, 9])
* Binding to e.g. double: python_cxx.IntVector([2, 4, 6])
* Or wrap an operation like decrement: [0, 1, 2]!
Executing a C++ class method on [1. 1. 1. 1. 1.] gives:

Thread 1 "python3.12" hit Breakpoint 1.1, ExpAverage::step (this=0x7ffff49cd708, x=...) at ../src/array.cpp:18
18           void step(nanobind::ndarray<nanobind::c_contig, nanobind::device::cpu> x) {
(gdb) 

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

python_cxx-0.1.0b21.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

python_cxx-0.1.0b21-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (73.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file python_cxx-0.1.0b21.tar.gz.

File metadata

  • Download URL: python_cxx-0.1.0b21.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python_cxx-0.1.0b21.tar.gz
Algorithm Hash digest
SHA256 1efbe4e461bfa1d912fe4cb63c9cdeeada59b1761316a845d54ba3c9c5b23fbd
MD5 289a3de428f2f317886dc9da7929fc8a
BLAKE2b-256 aa5c66eecafa9a9ce7d4bc9a99738bf18627cb11337c9b47abccc132af005917

See more details on using hashes here.

File details

Details for the file python_cxx-0.1.0b21-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: python_cxx-0.1.0b21-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 73.3 kB
  • Tags: CPython 3.14, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python_cxx-0.1.0b21-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd2420ca1952c5e2ac3513b502874f9f7f01e768a3c8e1b37a73f65feea1ccfd
MD5 dfcbb93d388e06688d5192990f41e1a8
BLAKE2b-256 b7378f74b08bf34fcc947c3cd97e0d9f0da81d91fd4a7894d5ad4d0520205ee3

See more details on using hashes here.

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