IPC implementation of ctypes API
Project description
cpypes
cpypes is a drop-in substitute for ctypes that runs the compiled
code in a separate process.
This provides separation between the Python process and the process running the compiled code, which could allow you to debug the compiled code more easily, or even run it on a separate machine!
Quick Start
pip install cpypes
>>> import cpypes
>>> libc = cpypes.CDLL("libc.so.6")
>>> dst = cpypes.create_string_buffer(10)
>>> libc.strncpy(dst, b"Hello, world!", 5)
-1783489504
>>> dst.value
b'Hello'
By default, cpypes starts up a server for itself. You can also start
the server manually and then use
cpypes.connect(("127.0.0.1", 5555))
to connect to it (you should do right after importing it). The server
is typically installed at .venv/cpypes/server/main. To start it
listening on a port, run
.venv/cpypes/server/main 5555
Use Case Examples
-
You write a C library (
.so) and want to write unit tests for the public functions. You can write the unit tests in Python, run them withpytest, and run the library undervalgrind! -
Say you have a
.soon an embedded Linux device that you want to test out. You can run thecpypesserver on the embedded device (you'll need to compile the server for that architecture, and make sure the embedded device haslibffion it) and then connect to it withcpypesrunning on your laptop!
Requirements
cpypes currently supports only Linux.
cpypes requires make, gcc, and libffi-dev to build the server.
Caveats
Because it runs the compiled code in a separate process, cpypes is
inherently unsuitable for some applications. For example, running
printf in cpypes will always write to the server's standard output
rather than the current process's (which, incidentally, will most
likely cause a fatal error for cpypes). You can certainly use
file descriptors in the server; you just need to make sure you don't
try to use the client's file descriptors in the server's context,
or anything equivalent.
Coming Soon
-
Option to start server under
valgrind. -
Support for more types.
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
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 cpypes-0.0.1.tar.gz.
File metadata
- Download URL: cpypes-0.0.1.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82de92c29ad23dcc089ca32ff29ddf874d8edb8fa9aaeb1cf99d9c8b1a98b544
|
|
| MD5 |
41938f1b52e96b56bd4bcea17d3e5201
|
|
| BLAKE2b-256 |
5879bc3e583eb41d31492ff41f91618e2280361a9a9b0d473cd971f6d7f8b2d3
|
File details
Details for the file cpypes-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cpypes-0.0.1-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0f675b19753fbd2ac9dc739fb210d9b1f63c94f540480876543c5d44c844392
|
|
| MD5 |
f9014ac9b949fcf87b53cfbc61e71467
|
|
| BLAKE2b-256 |
63fba522f57e8d5b37fc817c3ddad6c758cc2cd6a2d81783dd4fe430a1500020
|