Skip to main content

A Swift programming language symbol demangler/normalizer library for Python on Windows

Project description

pyswiftdemangler

A Swift programming language symbol demangler/normalizer library for Python on Windows (unofficial).
It uses Python's ctypes to call the official Swift DLL for demangling Swift mangled symbols.

Author: https://github.com/its-me-abi
Date: 18/10/2024


Features

  • Demangles Swift symbol names using the official Swift DLL (swiftDemangle.dll).
  • Exposes a simple Python class interface.
  • Provides command-line usage for convenience.
  • Offers a test mode to verify correct demangling.
  • Installable as a PyPI package.

Installation

From PyPI (recommended)

pip install pyswiftdemangler

From source

git clone https://github.com/its-me-abi/pyswiftDemangler.git
cd pyswiftDemangler
pip install -e .

Requirements

  • Python 3.6 or higher
  • Windows OS (due to DLL usage)
  • swiftDemangle.dll (included in the package, or provide a custom path)

Usage

As a Library

from pyswiftdemangler import demangler

d = demangler()  # or demangler(path_to_dll)
demangled = d.get_demangled_name("_TtuRxs8RunciblerFxWx5Mince6Quince_")
print(demangled)  # Outputs: <A where A: Swift.Runcible>(A) -> A.Mince.Quince

From the Command Line

pyswiftdemangler --name <mangled_swift_symbol>

Example:

pyswiftdemangler --name _TtuRxs8RunciblerFxWx5Mince6Quince_

Test Mode

To run the built-in test (checks a hardcoded input/output pair):

pyswiftdemangler --test

API Reference

demangler class

from pyswiftdemangler import demangler

d = demangler(path="")

Parameters:

  • path (str, optional): Path to the swiftDemangle.dll. Defaults to the bundled DLL.

Methods:

  • get_demangled_name(name, max_buffer_size=0)
    • Returns the demangled symbol as a string or None if demangling fails.
    • name (str): The mangled Swift symbol name.
    • max_buffer_size (int): Optional maximum buffer size for output.

Example:

from pyswiftdemangler import demangler

demangler_instance = demangler()
demangled = demangler_instance.get_demangled_name("_TtuRxs8RunciblerFxWx5Mince6Quince_")
print(demangled)  # <A where A: Swift.Runcible>(A) -> A.Mince.Quince

File Structure

pyswiftDemangler/
├── pyswiftdemangler/
│   ├── __init__.py          # Package initialization
│   ├── core.py              # Main demangler implementation
│   ├── cli.py               # Command-line interface
│   └── lib/
│       └── swiftDemangle.dll # Swift DLL (required for demangling)
├── README.md                # This file
├── LICENSE                  # MIT License
├── CHANGELOG.md             # Version history
├── pyproject.toml           # Modern Python packaging config
├── setup.py                 # Legacy setup script
├── setup.cfg                # Setup configuration
└── MANIFEST.in              # Package manifest

Notes

  • Only works on Windows due to DLL usage.
  • Ensure the DLL path is correct; the default expects it in the lib folder within the package.
  • If you get a DLL loading error, verify that swiftDemangle.dll exists in the package lib directory.

Example

import pyswiftdemangler

demangler = pyswiftdemangler.demangler()
print(demangler.get_demangled_name("_TtuRxs8RunciblerFxWx5Mince6Quince_"))
# Output: <A where A: Swift.Runcible>(A) -> A.Mince.Quince

Development

Running Tests

pyswiftdemangler --test

Building the Package

pip install build
python -m build

This creates dist/ directory with wheel (.whl) and source (.tar.gz) distributions.

Publishing to PyPI

pip install twine
twine upload dist/*

License

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


Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

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

Source Distribution

pyswiftdemangler-0.1.1.tar.gz (110.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyswiftdemangler-0.1.1-py3-none-any.whl (108.6 kB view details)

Uploaded Python 3

File details

Details for the file pyswiftdemangler-0.1.1.tar.gz.

File metadata

  • Download URL: pyswiftdemangler-0.1.1.tar.gz
  • Upload date:
  • Size: 110.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pyswiftdemangler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 92bb598d7a6513e5bd5ae6198ddd1b3fe083e95b4f6afdedb2e4fd14911dad6e
MD5 92ed8348871dbd2112e96538be124e37
BLAKE2b-256 ae69e64e8a6822e05c0ad0f1777fdf8bac32e864740ee74b7e3b4fbadd48d862

See more details on using hashes here.

File details

Details for the file pyswiftdemangler-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyswiftdemangler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 308be45d018c28e64f85d6df6819ce19c3004d3af22de1a77c72ac5b9a45c444
MD5 3147909ec36add399df4bfa5d7999afe
BLAKE2b-256 2f596fc2430065244a0417e774fd459ff6ef8656d73c3018f4da703d7db8f257

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page