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?
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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With