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
Release history Release notifications | RSS feed
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.1.tar.gz
(3.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qkbind-0.1.1.tar.gz.
File metadata
- Download URL: qkbind-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74e743884ddbc2bec5848833ceb6d1d204e0dca952f1e22c17c969e1a3fed67a
|
|
| MD5 |
871085ffd2c597099b78be2d22c02b70
|
|
| BLAKE2b-256 |
d9a903f57cfdbda6f7febc40b8884ef59c6fabf1636c0474ecb64608875fcdb3
|
File details
Details for the file qkbind-0.1.1-py3-none-any.whl.
File metadata
- Download URL: qkbind-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c6787a4e5159b393c5c33ed6561245cb1f93a540a95512b715a20f620a16ea0
|
|
| MD5 |
6462f1f4c0d18d6dd0ee5fba30d5798e
|
|
| BLAKE2b-256 |
da9b10c0d1620eb3697e754a38f1d7a0204cc8db29fe46bd3ae32f02db9ba448
|