Skip to main content

Swiftlet PyPI Downloads

Swiftlet provides Python bindings for Swiftlet, a high-performance parsing library built in Rust. It accepts an EBNF-style grammar and parses input text into a tree of Tree and Token nodes.

Features

  • Parse context-free grammars from a string or file.
  • Choose the parsing algorithm with earley or clr.
  • Control ambiguity handling with resolve or explicit.
  • Inspect the parse result as Tree and Token objects from Python.
  • Context-aware tokenization support, including parser-guided terminal selection for ambiguous token sets.

Installation

Build and install the package from the swiftlet directory:

pip install swiftlet

Example

from swiftlet import Swiftlet, Transformer

class Calculate(Transformer):
    def start(self, child):
        return child[0]
    
    def expr(self, child):
        return child[0]
    
    def add(self, child):
        return child[0] + child[2]
    
    def sub(self, child):
        return child[0] - child[2]
    
    def mul(self, child):
        return child[0] * child[2]
    
    def div(self, child):
        return child[0] / child[1]
    
    def terms(self, child):
        return child[0]

def main():
    grammar = """
    start: expr
    expr: expr "+" terms -> add
        | expr "-" terms -> sub
        | terms
    terms: terms "*" INT -> mul
        | terms "/" INT -> div
        | INT
    %import (WS, INT)
    %ignore WS
    """

    text = "12 + 10 - 8 * 2 + 4"
    parser = Swiftlet(grammar)
    parsed_text = parser.parse(text)
    
    calculate = Calculate()
    result = calculate(parsed_text)

    parsed_text.pretty_print()
    print("\nResult: ", result)


if __name__ == "__main__":
    main()

Output

start
   add
     sub
       add
         expr
           terms   12
         +
         terms   10
       -
       mul
         terms   8
         *
         2
     +
     terms   4

Result:  10

Usage

Create a parser from grammar text:

from swiftlet import Swiftlet

parser = Swiftlet(
    grammar,
    start="start",
    algorithm="earley",
    ambiguity="resolve",
    debug=False,
)

Create a parser from a grammar file:

from swiftlet import Swiftlet

parser = Swiftlet.from_file("file_name")

Parse text and inspect the returned tree:

tree = parser.parse("42")
print(tree.get_name())
print(tree.get_children()[0].get_children()[0].get_word())

Notes

  • algorithm accepts earley or clr.
  • ambiguity accepts resolve or explicit.
  • parse() returns a Tree on success and raises ValueError or RuntimeError on failure.

For more examples, please check notebooks

Release files for swiftlet 0.2.2

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

Built distributions (wheels)

Table of built distributions (wheels) for swiftlet 0.2.2
File Interpreter ABI Platform
swiftlet-0.2.2-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
swiftlet-0.2.2-cp310-abi3-manylinux_2_34_x86_64.whl CPython 3.10 abi3 Linux glibc 2.34+ x86-64 Details
swiftlet-0.2.2-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details

Total release size: 2.8 MB

Release files / swiftlet-0.2.2-cp310-abi3-win_amd64.whl

Download URL swiftlet-0.2.2-cp310-abi3-win_amd64.whl
Size 902.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
32885ce13bb21e2540c06fe1cb3516aaec7ace806c1317c6865af62986c44984
BLAKE2b-256 checksum
How to use checksums
642fb5d43680c2a37e69bd5b550a860dcc750ba993fc3c40b40d1d1241fa5a90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 17, 2026.

Transparency log

Release files / swiftlet-0.2.2-cp310-abi3-manylinux_2_34_x86_64.whl

Download URL swiftlet-0.2.2-cp310-abi3-manylinux_2_34_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
5508c158857edd97383d66b87886f160bd2a1721f7e4332d2f2a8befdce4d463
BLAKE2b-256 checksum
How to use checksums
8477f9a495ebd9924f7f558757aea466531f004e45fa95d2ba03f191d770eda5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 17, 2026.

Transparency log

Release files / swiftlet-0.2.2-cp310-abi3-macosx_11_0_arm64.whl

Download URL swiftlet-0.2.2-cp310-abi3-macosx_11_0_arm64.whl
Size 906.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4b1bdd699d3e90d89b0396e2687264ef0d327dc2d27d44b2722e796e5bf0df64
BLAKE2b-256 checksum
How to use checksums
03017a28696be98c4d4f1b627e9128e4a833433d43b84c96cc13515877f58347
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.2 This release

3 release files

0.2.1

3 release files

0.2.0

3 release files

0.1.5

3 release files

0.1.4

3 release files

0.1.3

3 release files

0.1.2

3 release files

0.1.1

3 release files

0.1.0

4 release files

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