Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Thrift Python 3 support

I compiled my test.thrift file using:

thrift -gen py test.thrift

Then i tried to import the created files:

from test.ttypes import *

When I use Python 2.7 the import works but with Python 3.4 it raises

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/art/SerTest/addressThrift/gen-py/test/ttypes.py", line11, in <module>
from thrift.transport import TTransport
File "/usr/local/lib/python3.4/dist-
packages/thrift/transport/TTransport.py", line 20, in <module>  
from cStringIO import StringIO
ImportError: No module named 'cStringIO'

I tried to run: sudo python3 setup.py install and got many exceptions, all seems to be related to python 2 vs 3 problems. for example:

File "/usr/local/lib/python3.4/dist-
     packages/thrift/transport/TSSLSocket.py", line 99
except socket.error, e:
                   ^
SyntaxError: invalid syntax

I addition there is a warning thats seems important:

/usr/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'use_2to3'

Googling Thrift Python 3 support seems contradicting.
Those say that there is no support:
Does cql support python 3?
https://issues.apache.org/jira/browse/THRIFT-1857
And here I understand from the subtext that it does:
Thrift python 3.4 TypeError: string argument expected, got 'bytes'
Python 3.4 TypeError: input expected at most 1 arguments, got 3
https://issues.apache.org/jira/browse/THRIFT-2096
So does Thrift support Python 3.X? If so what did I missed?

like image 772
Rtik88 Avatar asked Aug 26 '15 14:08

Rtik88


People also ask

What is Thrift Python?

Thrift is provided as a set of Python packages. The top level package is thrift, and there are subpackages for the protocol, transport, and server code. Each package contains modules using standard Thrift naming conventions (i.e. TProtocol, TTransport) and implementations in corresponding modules (i.e. TSocket).

When should I use Apache Thrift?

Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages.

Is Apache Thrift an RPC?

Apache Thrift is a set of code-generation tools that allows developers to build RPC clients and servers by just defining the data types and service interfaces in a simple definition file.


1 Answers

There is a better solution to this. Instead of waiting the official python 3 support, why not use our python implementation of thrift?

https://github.com/eleme/thriftpy

it fully supports python 3, and pypy, and pypy3.

like image 200
WooParadog Avatar answered Sep 29 '22 14:09

WooParadog