This is simple .pyi stubs generator from thrift interfaces. Motivation for this project is to have autocomplete and type checking for dynamically loaded thrift interfaces
Installation
pip install thrift-pyi
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
–strict-optional
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, fields without default values cannot appear after fields with default values. Therefore by default all fields are optional with default to None. This is compliant to thriftpy2.
However, if you want more strict behaviour you can specify –strict-optional option. For the case above, the following stubs will be generated:
from dataclasses import dataclass
@dataclass
class TodoItem:
id: int
type: int = 1
text: str
Development
To install pre-commit hooks:
pre-commit install
To run the all tests run:
tox
Metadata
Release files for thrift-pyi 2.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| thrift_pyi-2.6.0.tar.gz | 10.8 kB | Without provenance | Details for thrift_pyi-2.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| thrift_pyi-2.6.0-py3-none-any.whl | Python 3 | none | any | Details for thrift_pyi-2.6.0-py3-none-any.whl |
Total release size: 23.7 kB
Release files / thrift_pyi-2.6.0.tar.gz
| Download URL | thrift_pyi-2.6.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2941f04be44503b785b5af8509cb0eded0b0417cf8f4da10e8be552ba5bfccc8
|
|
BLAKE2b-256 checksum How to use checksums |
5f5673e2ff4fc90748679766ea47c793db93b9e0ce8764760caa291286984b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.9.25 Linux/6.17.0-1018-azure
|
Release files / thrift_pyi-2.6.0-py3-none-any.whl
| Download URL | thrift_pyi-2.6.0-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18664950390c9ec8dc0a2330743aac86a41b7e7e1d4f9bd7f2b4079a05a24308
|
|
BLAKE2b-256 checksum How to use checksums |
8f0170f005666c2df422bdde3a1b13e86eb6f2aa108d969fe62894541ee96e27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.9.25 Linux/6.17.0-1018-azure
|
Security for thrift-pyi 2.6.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.