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.
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 theswiftDemangle.dll. Defaults to the bundled DLL.
Methods:
get_demangled_name(name, max_buffer_size=0)- Returns the demangled symbol as a string or
Noneif demangling fails. name(str): The mangled Swift symbol name.max_buffer_size(int): Optional maximum buffer size for output.
- Returns the demangled symbol as a string or
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
libfolder within the package. - If you get a DLL loading error, verify that
swiftDemangle.dllexists in the packagelibdirectory.
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
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 pyswiftdemangler-0.1.0.tar.gz.
File metadata
- Download URL: pyswiftdemangler-0.1.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36e70310808f6fccf436244ad4c3338e012aa50664c8b86dc7efa8b68c99b568
|
|
| MD5 |
577b5db02ee22e4aa783bf6dbe652b87
|
|
| BLAKE2b-256 |
cb1a90002bbe86623b15f49cab7c91564011099c703e0b160d11917b64e45ccb
|
File details
Details for the file pyswiftdemangler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyswiftdemangler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b4a4fab8955114a7764315822394b91a939144bb293c0ebce0502c05006c7fd
|
|
| MD5 |
50358b7d580be6d54f8d88488bccc3b2
|
|
| BLAKE2b-256 |
fd3d09f9935e7f1e83b38a02e4a97d2442a9b762eea9ba8cfabd4e3a3e4913a2
|