Skip to main content

a thrift parser (antlr4)

Project description


pip install thrift-parser

Thrift.g4 is from


from thrift_parser import parse_file

lexer, tokens, parser, document = parse_file('tutorial.thrift')

or smiple

from thrift_parser import ThriftData

thrift_data = ThriftData.from_file('tutorial.thrift')


or you can try antlr's way

from antlr4 import FileStream
from antlr4 import CommonTokenStream
from antlr4 import ParserRuleContext

from thrift_parser.ThriftLexer import ThriftLexer
from thrift_parser.ThriftParser import ThriftParser

def main(file):
    input_stream = FileStream(file, encoding='utf8')
    lexer = ThriftLexer(input_stream)
    stream = CommonTokenStream(lexer)
    parser = ThriftParser(stream)
    ctx = ParserRuleContext()

    parser.enterRule(ctx, 0, 0)
    document = parser.document()
    return document

Why ?

python thrift parser --> thrift-fmt --> auto format my thrift files in one style


  1. more ast operate, fake_token, fake_context
  2. other language?

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

thrift-parser-1.0.7.tar.gz (27.2 kB view hashes)

Uploaded Source

Built Distribution

thrift_parser-1.0.7-py3-none-any.whl (29.6 kB view hashes)

Uploaded Python 3

Supported by

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