Skip to main content

This is simple `.pyi` stubs generator from thrift interfaces

Project description

Travis-CI Build Status Coverage Status Codacy Badge Requirements Status PyPI Package latest release PyPI Wheel Supported versions MIT License

This is simple .pyi stubs generator from thrift interfaces. Motivation for this project was to have autocomplete and type checking for dynamically loaded thrift interfaces

Installation

pip install thriftpyi

Quickstart

Sample usage:

$ thriftpyi example/interfaces --output example/app/interfaces

Additionally to generated stubs you might want to create __init__.py that will load thrift interfaces, for example:

from pathlib import Path
from types import ModuleType
from typing import Dict

import thriftpy2

_interfaces_path = Path("example/interfaces")
_interfaces: Dict[str, ModuleType] = {}


def __getattr__(name):
    try:
        return _interfaces[name]
    except KeyError:
        interface = thriftpy2.load(str(_interfaces_path.joinpath(f"{name}.thrift")))
        _interfaces[name] = interface
        return interface

To see more detailed example of usage refer to example app

Caveats

Python and thrift are very different at argument handling. For example in thrift the following will be correct declaration:

struct TodoItem {
    1: required i32 id
    3: optional i32 type = 1
    2: required string text
}

In python attributes without a default cannot follow attributes with one. Nevertheless, library doesn’t enforce any checks with that case and will generate .pyi as is:

from dataclasses import dataclass

@dataclass
class TodoItem:
    id: int
    type: int = 1
    text: str

Development

To run the all tests run:

tox

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-pyi-0.1.0b1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

thrift_pyi-0.1.0b1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file thrift-pyi-0.1.0b1.tar.gz.

File metadata

  • Download URL: thrift-pyi-0.1.0b1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.7.1 Linux/4.15.0-1028-gcp

File hashes

Hashes for thrift-pyi-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 eff3972c38e34c185cd1c40997cbf66490b12d4923055598ce14930105aef19c
MD5 5bb25b7372a058b40cb1892c74bae5d3
BLAKE2b-256 8302251e97a5ebf29bdfad80f04f14cc426c9f4e23cd6e555effa3f231fa4070

See more details on using hashes here.

File details

Details for the file thrift_pyi-0.1.0b1-py3-none-any.whl.

File metadata

  • Download URL: thrift_pyi-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.7.1 Linux/4.15.0-1028-gcp

File hashes

Hashes for thrift_pyi-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7df799644aa5fd1cb67d2b64d3617b831dc24e4150cba1eaa5f8182707d2c53
MD5 5dfc3577acfeb0879f6812c798df1f66
BLAKE2b-256 18fdbba55c133078e9bdca9db7dfd9e1b0bc143c4087bb3ced16e0d37afffdf1

See more details on using hashes here.

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