Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Compile and Link C-API modules on Import

Project Description

🐚 About

c is a Python project providing a metapath hook for loading C extension modules without prior compilation by a ‘setup.py’ script. It uses the sysconfig module to extract the necessary information for compiling an extension module.

Loadable modules are identified by the ‘.py.c’, ‘.py.m’, and ‘.py.c++’ suffix. Composition of multiple files is not directly supported, but preprocessor directives may be used in order to combine multiple files.

Sample

Typical usage:

>>> import package.libfoo
>>> package.libfoo.return_true()
True

Where:

package/
        __init__.py
        libfoo.py.c

libfoo.py.c:

/*
 * libfoo.py.c - test library for the c loader
 */
#include <Python.h>
#include <structmember.h>

static PyObject *
return_true(PyObject *self)
{
        Py_INCREF(Py_True);
        return(Py_True);
}

/* METH_O, METH_VARARGS, METH_VARKEYWORDS, METH_NOARGS */
static PyMethodDef methods[] = {
        {"return_true", (PyCFunction) return_true, METH_NOARGS, "return `True`"},
        {NULL}
};

static struct PyModuleDef module = {
        PyModuleDef_HEAD_INIT,
        "package.libfoo",       /* name of module */
        NULL,                                   /* module documentation, may be NULL */
        -1,                                     /* size of per-interpreter state of the module,
                                                                or -1 if the module keeps state in global variables. */
        methods,
};

PyMODINIT_FUNC
PyInit_libfoo(void)
{
        PyObject *mod;
        mod = PyModule_Create(&module);
        return(mod);
}
Release History

Release History

This version
History Node

0.6.0

History Node

0.5.0

History Node

0.3.0dev

History Node

0.2.0dev

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
c-0.6.0.tar.gz (6.4 kB) Copy SHA256 Checksum SHA256 Source Aug 7, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting