Full of Eels
FullOfEels is an assistant program to generate the skeleton code for a handcrafted artisanal Python module to be implemented in native C.
It is not a replacement for SWIG or SIP. If you have an existing C/C++ library and want to create a Python wrapper with the same API, either of those will do just fine. Nor is it a replacement for ctypes.
FullOfEels works in the opposite direction. You start by specifying the Python API that you want: module, classes, methods, and functions. This program will create the initial .h/.c files for you, generating empty C functions with argument parsing code, struct definitions for the object and type, module init function ... all the the boring but necessary bits. You then fill them out with working C code.
How do you specify the Python API you want? By writing it in Python.
You create a module that defines what the functions and classes will
be, with all the arguments and methods, but none of the code that
defines how it works - methods and functions should all just pass.
FullOfEels keeps docstrings and some globals, but actual statements
are discarded.
Why might you prefer this? Because you can design a more Pythonic API. The great advantage of SWIG/SIP is that the API is already known and (ideally) documentation exists. The disadvantage is that you're just recreating a C/C++ API in Python, and that programmers will have to be able to understand C/C++ to understand the documentation. There are times when this is the best solution. Fullofeels is for when it isn't.
Written by Hugh(Hugo) Fisher, Canberra Australia, 2016-now.
Released under MIT license
All feedback welcome: hugo.fisher@gmail.com (Yes, hugo not hugh)
Example
The Python "Extending Python with C or C++" web pages
start by creating a spam module with a single system() function.
With fullOfEels you start this by writing spam.py which is just
def system(command):
"""Execute a shell command."""
pass
Then you run
python -m fullofeels -print spam.py
which will create
spam.h
spam.c
setup.py
Look inside and you'll see all the skeleton code needed for the complete Python extension module. Run
python setup.py build_ext --inplace
and you will have a valid module. From your Python interpreter you can
import it and invoke the spam.system("hello") function, which will just
print out the function name and arguments (specified by the -print CLI option).
Because fullOfEeels is an assistant, not an automated solution, you still need to fill in the function body yourself to make it do anything useful.
For the "Defining New Types" web example you would write custom.py:
class Custom(object):
"""Custom objects"""
def __new__(cls):
pass
def __init__(self, first, last, number: int):
pass
def __del__(self):
pass
def name(self) -> str:
"""Return the name, combining the first and last name"""
pass
and again run fullOfEels on it. The generated C code will have the all the code necessary to declare and initialize the Custom type structure. As before you could build this module, import it, and even create Custom objects. But without additional code they won't do anything and won't have any attributes or properties.
TODO
Heap allocated types
Look at new Python C API for 3.10+
Tested on
Python 2.7 Fedora Core 24, MacOS 10.14 XCode 11
Python 3.5 Fedora Core 24
Python 3.6 Windows 8.1 MSVC 2017
Python 3.7 Fedora Core 31, Windows 10 MSVC 2019
Python 3.9 Fedora Core 31
Versions
1.7 Mar 2021 Type annotations recognised for parameters
1.6 Feb 2021 Automate testing on Windows, cleanup for PyPI release
1.5 Jan 2019 Replace separate program with -m fullofeels package
1.4 Nov 2017 Generate setup.py for module
1.3 Oct 2017 Properties on class become C fields in object struct
1.2 Feb 2017 Can specify argument types for PyArg_ParseTuple
1.1 Nov 2016 Special slots for collections, numbers, buffer interface
1.0 Apr 2016 Modules, objects, classes, methods
Metadata
Release files for fullofeels 1.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fullofeels-1.7.0.tar.gz | 29.0 kB | Without provenance | Details for fullofeels-1.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fullofeels-1.7.0-py3-none-any.whl | Python 3 | none | any | Details for fullofeels-1.7.0-py3-none-any.whl |
Total release size: 64.0 kB
Release files / fullofeels-1.7.0.tar.gz
| Download URL | fullofeels-1.7.0.tar.gz |
|---|---|
| Size | 29.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b3e8d7b5099d9dbe480e6ec0a0cf19de900299c323a7f42bd9c4eee1b4a102e
|
|
BLAKE2b-256 checksum How to use checksums |
56a77b271e573739e90a74c1d130c1115597ee298ee17283ef16ecc64b2d4ab8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9
|
Release files / fullofeels-1.7.0-py3-none-any.whl
| Download URL | fullofeels-1.7.0-py3-none-any.whl |
|---|---|
| Size | 35.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5adc9e3885d24bc10340f55e1646f8ff3aac211f5bed8cfd8dac9723e94e3813
|
|
BLAKE2b-256 checksum How to use checksums |
ca0f3e5a8f64cb2931d03ce6b919e8262af4d43d2f55713001b0bd0660d34860
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9
|
Security for fullofeels 1.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.