Skip to main content

Lightweight Python bindings for C

Project description

qkbind

Lightweight Python bindings for C

Installation

pip install qkbind

Or include directly in your project:

#include <qkbind/qkbind.h>

Example

#include <qkbind/qkbind.h>

// Your C struct
typedef struct {
    float* data;
    int size;
} Vector;

Vector* vector_create(int size) { /* ... */ }
void vector_free(Vector* v) { /* ... */ }
Vector* vector_add(Vector* a, Vector* b) { /* ... */ }

// Python bindings (just a few lines!)
QKBIND_WRAP(Vector, Vector)
QKBIND_INIT(Vector, Vector, vector_create(size),
    int size;
    if (!PyArg_ParseTuple(args, "i", &size)) return -1;
)
QKBIND_DEALLOC(Vector, vector_free)
QKBIND_BINOP(Vector, add, vector_add)
QKBIND_PROPERTY_INT(Vector, size, size)

// Type definition
static PyNumberMethods PyVector_as_number = {
    .nb_add = (binaryfunc)PyVector_add,
};

QKBIND_TYPE_BEGIN(Vector, vector_c)
    .tp_as_number = &PyVector_as_number,
QKBIND_TYPE_END

// Module
QKBIND_MODULE_BEGIN(vector_c)
    QKBIND_MODULE_ADD_TYPE(Vector)
QKBIND_MODULE_END

Use in Python:

import vector_c

v1 = vector_c.Vector(100)
v2 = vector_c.Vector(100)
v3 = v1 + v2  # Calls C code!
print(v3.size)

License

MIT

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

qkbind-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

qkbind-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qkbind-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for qkbind-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7291b2adb5e0712aa465cf4ce03413045c7687718ca3c05c449ca1d637e4cbc9
MD5 36387ed21d3a1e8d22825784582d155b
BLAKE2b-256 ad885e0346f9b44ed6ac9c454516a1c9f0a5b7cb16a835c7a25d469947705215

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qkbind-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for qkbind-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6bb764276b2644b82567da7a8876182b89999eb2a998a82d57aabd3f4d6f6a0
MD5 96f94d84b55d3c9ea58c0f824b8fe433
BLAKE2b-256 f1920345f2a63e3dd73c463fee158ae327755fb4eb3c5edc8989d949a63631ba

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