Skip to main content

dwarfbind

Generate Python ctypes bindings from shared libraries.

A tool to help generate Python ctypes bindings from shared libraries. It reads DWARF debug information from library files to understand C structures and types, then generates equivalent Python classes.

Features

  • Reads DWARF debug information to understand C types and structures
  • Generates Python ctypes classes that match the C structures
  • Handles complex type relationships and dependencies
  • Creates proper Python modules with types, symbols, and constants submodules
  • Provides clean imports like from mylib.types import MyStruct
  • Extracts constants and macros from header files
  • Automatically discovers library paths using pkg-config
  • Supports relative header paths (e.g., freerdp/freerdp.h with -I /usr/include/freerdp3)

Requirements

  • Python 3.12 or newer
  • Debug symbols for the libraries you want to analyze:
    # Install debug symbols for a specific package
    sudo dnf debuginfo-install libfreerdp3
    
    # Or enable debuginfo repos and install manually
    sudo dnf install 'dnf-command(debuginfo-install)'
    sudo dnf debuginfo-install libfreerdp3
    
  • C preprocessor (cpp) for header file analysis:
    # Install gcc which includes cpp
    sudo dnf install gcc
    
  • pkg-config for library and include path discovery:
    # Install pkg-config
    sudo dnf install pkgconf-pkg-config
    

Installation

Usage

Generate bindings for a shared library:

# Basic usage
dwarfbind /usr/lib/libexample.so

# Extract constants from headers
dwarfbind --headers example.h /usr/lib/libexample.so

# Add include paths for header processing
dwarfbind -I /usr/include -I /usr/local/include --headers example.h /usr/lib/libexample.so

# Specify output file
dwarfbind -o bindings.py /usr/lib/libexample.so

# Process multiple libraries at once
dwarfbind -o output/ libone.so libtwo.so

# Use pkg-config to find library and include paths
dwarfbind --pkgconfig freerdp3 --headers freerdp/freerdp.h

# Enable verbose output
dwarfbind -v /usr/lib/libexample.so

The generated bindings provide a clean Python API:

from ctypes import *
from example.types import MyStruct
from example.symbols import my_function
from example.constants import BUFFER_SIZE

# Create and use structures
structure = MyStruct()
structure.field = BUFFER_SIZE

# Call library functions
my_function.argtypes = [POINTER(MyStruct)]
my_function.restype = c_int
result = my_function(byref(structure))

Development

To set up a development environment:

# Install Python 3.12 or newer
uv python install 3.12
# Optional: install shims for python/python3
uv python install --default

# Create a virtual environment
uv venv -p 3.12
# Optional: activate the environment
source .venv/bin/activate

# Sync dependencies (including dev tools)
uv sync

# Run tests
uv run pytest

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. See CONTRIBUTING.md for development setup, workflow guidelines, and coding style.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for dwarfbind 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dwarfbind 0.1.4
File Size Uploaded Provenance Actions
dwarfbind-0.1.4.tar.gz 63.3 kB Without provenance Details for dwarfbind-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dwarfbind 0.1.4
File Interpreter ABI Platform Actions
dwarfbind-0.1.4-py3-none-any.whl Python 3 none any Details for dwarfbind-0.1.4-py3-none-any.whl

Total release size: 108.3 kB

Release files / dwarfbind-0.1.4.tar.gz

Download URL dwarfbind-0.1.4.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bd2a0337e90e52d3ceb2ccfb907556cee6048413c0934a60a33b9e13f4943caf
BLAKE2b-256 checksum
How to use checksums
8d9b2f495aac38dcaa9129e8e4cd6c526544995069d246a9fea52773f4f9fab8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.12

Release files / dwarfbind-0.1.4-py3-none-any.whl

Download URL dwarfbind-0.1.4-py3-none-any.whl
Size 45.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48970675f0cec64d163bd4bcb962e8887fa1f0a0a34f4fc9601fb42af33fe334
BLAKE2b-256 checksum
How to use checksums
18e1286960b2a2e97938a648d4eb85095ba3936710a27ef676f318e463645a95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.12

Security for dwarfbind 0.1.4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page