Skip to content
Code generation framework for multilingual web application development
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Thryft: a code generation framework for multilingual web application development


Thryft accepts Apache Thrift interface definitions and generates:

  • Java immutable models, service interfaces, abstract service stubs, unit test templates, logging service wrappers, and JSON-RPC servlet bridges to services
  • Python models and JSON-RPC service clients
  • TypeScript models, logging service wrappers, and JSON-RPC service clients
  • ElasticSearch mappings

Thryft is written in Python using a SPARK parser and syntax-directed translation.

Thryft does not share any code with Apache Thrift, and it is not intended to be a complete rewrite of the latter. Among other things, Thryft does not currently a number of secondary IDL features such as senums. Thryft's runtime library is also quite different from Apache Thrift's.

Thryft does have a number of features that are not present in Apache Thrift:

  • Support for additional "native" types using custom, dynamically-loaded code generators:
    • URLs
    • email addresses
    • BigDecimals
    • datetimes
  • Annotations in Javadoc-style comments that can generate:
    • Language-specific documentation: javadoc, jsdoc, sphinx
    • Validation code


    git clone git://


    python thryft/compiler/bin/thryft

Reads a .thryft.json configuration file in the current directory. See lib/.thryft.json for an example.

Runtime libraries

Thryft-generated code relies on runtime libraries in different languages.





libthryft on PyPI

Software architecture / source overview

The compiler ( is the heart of Thryft. The compiler:

  • accepts files in .thrift at its entry point (compile), along with an instance of Generator (, such as JavaGenerator (
  • lexes and parses them with SPARK (
  • creates an Abstract Syntax Tree (AST, classes in representing the constructs in the .thrift, such as the root document, struct types, fields, et al.
  • for every node in the AST, creates a corresponding instance of the class in the Generator e.g., JavaGenerator.Document
  • tells the root of the generator instance tree (JavaGenerator.Document, in this case) to save itself to files using the method

Coding conventions

PEP8, with a few additions:

  • All of the logic is part of a class method; there are no freestanding functions, except the ancient utility functions in
  • There is one class per file, and the file is the underscore_separated version of the CamelCase class name.
  • Protected methods are prefixed with _. Private methods are prefixed with __.
  • Methods, members, and parameters are listed in alphabetical order where feasible (i.e., not interdependent nested classes), ignoring leading underscores. The exception is __init__, which is always the first method listed. Nested classes and class constants come before all methods.

The repository uses the branching model.


2-clause BSD

You can’t perform that action at this time.