semvec/pypi-packages huggingface dataset:
thrift-converter 0.0.1
Thrift converting tools: json2thrift, thrift2json

thrift_converter
============

A python implemented tool for converting between json and thrift.


Install
------------

```bash
pip install thrift-converter
```


Why build this tool:
------------

1. Class in thrift gen-py use `thrift_spec()` to deserialize, but the `Enum` object is simply treated as `I32`, while in json, it's stored as string of name.   
2. `set` is not json serializable in standard json, we can treat `{'a', 'b', ..}` as `{None: ['a', 'b', ...]}` for distinction.


How to:
-----------
1. Parsing thrift ast by [ptsd](https://github.com/wickman/ptsd)
2. Deserializing thrift object by walking through ast recursively.


Todo:
-----------
- [ ] learn `ply` from [ptsd](https://github.com/wickman/ptsd)


Others
-----------

* [introspection-of-thrift-enums-in-python](https://grokbase.com/t/thrift/user/13614a6xd1/introspection-of-thrift-enums-in-python) discussed end with waiting for thrift upgrade(support for python enums)
* [thrift_json_decoder in twitter.common](https://github.com/twitter/commons/blob/master/src/python/twitter/thrift/text/thrift_json_decoder.py) can't handle with Enum
* [thrift_json_convertor based on thriftpy](https://github.com/xuanyuanking/thrift_json_convertor) too heavy


Usage
------------
example: [demo](https://github.com/shiyuan/thrift_converter/blob/master/test/')

```py
import json
from thrift_converter import JsonThriftConverter, ThriftJsonConverter

thrift_file = 'demo.thrift'
object_name = 'Group'

json2thrift = JsonThriftConverter(thrift_file).convert
thrift2json = ThriftJsonConverter(thrift_file).convert

obj = gen_fake_obj()
# Group(id=-1, worker_map={999: Worker(id=999, tasks=[Task(id=727, status=0, action=888, valid=True, msgs={'msg'})])})

js = thrift2json(obj, object_name)
js_str = json.dumps(js)
# {"id": -1, "worker_map": {"999": {"id": 999, "tasks": [{"id": 727, "status": 0, "action": "UP", "valid": true, "msgs": {"null": ["msg"]}}]}}}

obj = json2thrift(json.loads(js_str), object_name)
# Group(id=-1, worker_map={999: Worker(id=999, tasks=[Task(id=727, status=0, action=888, valid=True, msgs={'msg'})])})

```
wraphper 0.0.2
Python wrappers for PHP functions, when you just can't shake it.

![PyPi Status](https://img.shields.io/pypi/status/wraphper.svg) ![PyPi Python Version](https://img.shields.io/pypi/pyversions/wraphper.svg) ![PyPi Downloads](https://img.shields.io/pypi/dm/wraphper.svg) ![GitHub Issues](https://img.shields.io/github/issues-raw/aalaap/wraphper.svg) ![GitHub Commit Activity](https://img.shields.io/github/commit-activity/y/aalaap/wraphper.svg) ![PyPi License](https://img.shields.io/pypi/l/wraphper.svg) ![PyPi Version](https://img.shields.io/pypi/v/wraphper.svg)

# wraphper

Python wrappers for PHP functions, when you just can't shake it.

## Why?

If you're coming from PHP, you'll take a bit of time getting used to the new names or methods in Python. You could look up something like `"python str_replace"` everytime you want to do so, or you could just save time and use `php.str_replace('Hello', 'Goodbye', 'Hello, world!')`.

Why not?

## Installation

Pip it.

```
$ pip install wraphper
```

## Usage

Import the module and then fulfil your PHP fantasies in Python:

```python
import wraphper as php

a = [1, 2, 3]
php.count(a)
# outputs: 3
```

## Supported functions

This module is a work in progress. Not all functions are supported yet. The current list includes:

- [count](http://php.net/manual/en/function.count.php)
- [str_replace](http://php.net/manual/en/function.str-replace.php)

PRs with more functions are welcome!

## Performance and Security

wraphper doesn't internally call PHP to run these functions, it simply provides you a PHP-like function name that runs the Python equivalent. As such, performance is unaffected because only Python is running.

Similarly, there are no implications of this on security.

## Contributing

Follow these rules with contributed functions:

- The function must be an [native PHP function](http://php.net/manual/en/funcref.php), not from a third-party library. 
- The name of the function must match the original exactly. Otherwise, the purpose of this module is defeated.
- The function should take the exact same number of arguments as the original.
- The argument types must match the PHP types as closely as possible, so `string` is `str`, `int` is `int`, `array` is `list` or `dict`, etc.
- The function must throw an appropriate exception with the exact same error message from the PHP function.
- The function should avoid any pre- or post-processing of the argument or return value. The goal is not to match PHP functions' inputs and outputs, but to provide a PHP-familiar syntax for Python developers.

## Testing

Tests can be run by the following command:

```
$ python tests.py
```

## Compatibility

wraphper has been checked with Python 2.7 and 3.6, but there's no reason why it shouldn't work with older versions.

## Changelog

### 0.0.2 - 2019-01-29

- Added `str_replace`

### 0.0.1.post2 - 2019-01-28

- **BREAKING** Removed class to make it easier to import and use
- Added tuple support
- Added more tests
- Added changelog

### 0.0.1.post1 - 2019-01-26

- Added tests

### 0.0.1 - 2019-01-26

- Initial release with `count` function