This release is a pre-release and may not be stable for production use.
thrift-fmt
Thrift Formatter
can be used as command line tool thrift-fmt and python sdk thrift_fmt
use thrift-parser https://github.com/thrift-labs/thrift-parser as parser
Usage
Install
pip install thrift-fmt
Format files
format single file and print to stdout
thrift-fmt mythrift.thrift
format and overwrite the origin file
thrift-fmt -w mythrift.thrift
format a directory, this will overwrite the origin file, please keep in track
thrift-fmt -r ./thrift_files
Feature
- keep and align all comments
- patch list separator
- patch missed field's
requiredflag - align by the field's assign (like go)
- align by each field's part
- Format only part of the parsed thrift
example
struct Work {
1: required i32 number_a = 0, // hello
2: optional i32 num2 = 1, // xyz
}
align by each field's part
struct Work {
1: required i32 number_a = 0 , // hello
2: required i32 num2 = 1 , // xyz
3: required list<i32> num3 = [ 1, 2, 3 ] , // num3
11: required string str_b = "hello-world",
}
Use as sdk
use thrift_parser.ThriftData to parse from file or str
use ThriftFormatter or PureThriftFormatter format the parsed thrift data.
from thrift_fmt import ThriftFormatter, PureThriftFormatter
from thrift_parser import ThriftData
origin = '''
include "shared.thrift" // a
// work info
struct Work {
1: i32 num1 = 0,
2: required i32 num2, // num2 for
3: Operation op, // op is Operation
4: optional string comment,
5: map<string,list<string>> tags, //hello
}
'''
thrift = ThriftData.from_str(data)
out = ThriftFormatter(thrift).format()
assert out == '''
include "shared.thrift" // a
// work info
struct Work {
1: required i32 num1 = 0,
2: required i32 num2, // num2 for
3: required Operation op, // op is Operation
4: optional string comment,
5: required map<string, list<string>> tags, //hello
}
'''.strip()
# or only a single node
header = PureThriftFormatter().format_node(thrift.document.children[0])
assert header == 'include "shared.thrift"'
TODO
- better code
- support function default add new line
- support indent for /* */ multi line comment
- support tight map/list define ?
- any other feature ?
Dev
pdm install
pdm run pytest
pdm build
pdm run thrift-fmt --help
LICENSE
some thrift files in fixtures thrift was copy from https://github.com/apache/thrift/blob/master/tutorial/ , The Apache LICENSE
the Thrift.g4 in thrift-parser package was copy from https://github.com/antlr/grammars-v4
Metadata
Release files for thrift-fmt-fork 0.3.1a0
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-fmt-fork-0.3.1a0.tar.gz | 9.5 kB | Without provenance | Details for thrift-fmt-fork-0.3.1a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| thrift_fmt_fork-0.3.1a0-py3-none-any.whl | Python 3 | none | any | Details for thrift_fmt_fork-0.3.1a0-py3-none-any.whl |
Total release size: 19.0 kB
Release files / thrift-fmt-fork-0.3.1a0.tar.gz
| Download URL | thrift-fmt-fork-0.3.1a0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c48f897db9a8dbe096140e6241a7572dce914e1c256302e5b69401460251fe00
|
|
BLAKE2b-256 checksum How to use checksums |
febb64bf6c9e47fa6ba64df758c09d702f2620bc4836e17add66610d3798ec42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.23.1 CPython/3.13.2 Darwin/23.0.0
|
Release files / thrift_fmt_fork-0.3.1a0-py3-none-any.whl
| Download URL | thrift_fmt_fork-0.3.1a0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6013cf20a61749159e4a482a1b689c4df8613987fde288893d40028beedad2a
|
|
BLAKE2b-256 checksum How to use checksums |
fba15b9d71620f5812e65d34b7c26e67da22f3576bd128b814436d54bcb16138
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.23.1 CPython/3.13.2 Darwin/23.0.0
|
Security for thrift-fmt-fork 0.3.1a0
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.