blob: 27f22c82c080609721cbdbb02c8d64a05b1547b0 [file] [log] [blame] [view]
temporal40ee5512008-07-10 02:12:20 +00001Protocol Buffers - Google's data interchange format
jessecd04e9b2015-03-16 15:15:59 -07002===================================================
3
temporal40ee5512008-07-10 02:12:20 +00004Copyright 2008 Google Inc.
5
6This directory contains the Python Protocol Buffers runtime library.
7
temporalcc930432008-07-21 20:28:30 +00008Normally, this directory comes as part of the protobuf package, available
9from:
10
Feng Xiaoe4288622014-10-01 16:26:23 -070011 https://developers.google.com/protocol-buffers/
temporalcc930432008-07-21 20:28:30 +000012
13The complete package includes the C++ source code, which includes the
14Protocol Compiler (protoc). If you downloaded this package from PyPI
15or some other Python-specific source, you may have received only the
16Python part of the code. In this case, you will need to obtain the
17Protocol Compiler from some other source before you can use this
18package.
19
temporal742e4092008-08-27 19:25:48 +000020Development Warning
21===================
22
Peter Newmane2cc2de2020-08-10 19:08:25 +010023The pure python performance is slow. For better performance please
Jie Luodec49392020-03-25 15:59:46 -070024use python c++ implementation.
temporal742e4092008-08-27 19:25:48 +000025
temporal40ee5512008-07-10 02:12:20 +000026Installation
27============
28
Joshua Haberman301d3152022-02-08 18:31:50 -0800291) Make sure you have Python 3.7 or newer. If in doubt, run:
temporal40ee5512008-07-10 02:12:20 +000030
Misha Brukman67755702017-05-23 10:33:03 -040031 $ python -V
temporal40ee5512008-07-10 02:12:20 +000032
332) If you do not have setuptools installed, note that it will be
Misha Brukman67755702017-05-23 10:33:03 -040034 downloaded and installed automatically as soon as you run `setup.py`.
temporal40ee5512008-07-10 02:12:20 +000035 If you would rather install it manually, you may do so by following
Misha Brukman67755702017-05-23 10:33:03 -040036 the instructions on [this page](https://packaging.python.org/en/latest/installing.html#setup-for-installing-packages).
temporal40ee5512008-07-10 02:12:20 +000037
Misha Brukman67755702017-05-23 10:33:03 -0400383) Build the C++ code, or install a binary distribution of `protoc`. If
temporal40ee5512008-07-10 02:12:20 +000039 you install a binary distribution, make sure that it is the same
40 version as this package. If in doubt, run:
41
Misha Brukman67755702017-05-23 10:33:03 -040042 $ protoc --version
temporal40ee5512008-07-10 02:12:20 +000043
[email protected]a36f1b42013-02-26 17:49:03 +0000444) Build and run the tests:
temporal40ee5512008-07-10 02:12:20 +000045
Misha Brukman67755702017-05-23 10:33:03 -040046 $ python setup.py build
47 $ python setup.py test
[email protected]1eba9d92014-08-25 20:17:53 +000048
Misha Brukman67755702017-05-23 10:33:03 -040049 To build, test, and use the C++ implementation, you must first compile
50 `libprotobuf.so`:
Tamir Dubersteind632bc72015-04-10 15:26:58 -040051
Misha Brukman67755702017-05-23 10:33:03 -040052 $ (cd .. && make)
Tamir Dubersteind632bc72015-04-10 15:26:58 -040053
Misha Brukman67755702017-05-23 10:33:03 -040054 On OS X:
Tamir Dubersteind632bc72015-04-10 15:26:58 -040055
Misha Brukman67755702017-05-23 10:33:03 -040056 If you are running a Homebrew-provided Python, you must make sure another
57 version of protobuf is not already installed, as Homebrew's Python will
58 search `/usr/local/lib` for `libprotobuf.so` before it searches
59 `../src/.libs`.
Tamir Dubersteind632bc72015-04-10 15:26:58 -040060
Misha Brukman67755702017-05-23 10:33:03 -040061 You can either unlink Homebrew's protobuf or install the `libprotobuf` you
62 built earlier:
Tamir Dubersteind632bc72015-04-10 15:26:58 -040063
Misha Brukman67755702017-05-23 10:33:03 -040064 $ brew unlink protobuf
Tamir Dubersteind632bc72015-04-10 15:26:58 -040065
Misha Brukman67755702017-05-23 10:33:03 -040066 or
Tamir Dubersteind632bc72015-04-10 15:26:58 -040067
Misha Brukman67755702017-05-23 10:33:03 -040068 $ (cd .. && make install)
Tamir Dubersteind632bc72015-04-10 15:26:58 -040069
Misha Brukman67755702017-05-23 10:33:03 -040070 On other *nix:
Josh Haberman2bd813b2015-04-09 16:41:58 -070071
Misha Brukman67755702017-05-23 10:33:03 -040072 You must make `libprotobuf.so` dynamically available. You can either
73 install libprotobuf you built earlier, or set `LD_LIBRARY_PATH`:
74
75 $ export LD_LIBRARY_PATH=../src/.libs
76
77 or
78
79 $ (cd .. && make install)
80
81 To build the C++ implementation run:
82
83 $ python setup.py build --cpp_implementation
84
85 Then run the tests like so:
86
87 $ python setup.py test --cpp_implementation
temporal40ee5512008-07-10 02:12:20 +000088
89 If some tests fail, this library may not work correctly on your
90 system. Continue at your own risk.
91
92 Please note that there is a known problem with some versions of
93 Python on Cygwin which causes the tests to fail after printing the
Misha Brukman67755702017-05-23 10:33:03 -040094 error: `sem_init: Resource temporarily unavailable`. This appears
95 to be a [bug either in Cygwin or in
96 Python](http://www.cygwin.com/ml/cygwin/2005-07/msg01378.html).
97
Ian Hunter130bb072016-11-16 17:34:28 +000098 We do not know if or when it might be fixed. We also do not know
temporal40ee5512008-07-10 02:12:20 +000099 how likely it is that this bug will affect users in practice.
100
1015) Install:
102
Misha Brukman67755702017-05-23 10:33:03 -0400103 $ python setup.py install
jessecd04e9b2015-03-16 15:15:59 -0700104
Misha Brukman67755702017-05-23 10:33:03 -0400105 or:
jessecd04e9b2015-03-16 15:15:59 -0700106
Misha Brukman67755702017-05-23 10:33:03 -0400107 $ (cd .. && make install)
108 $ python setup.py install --cpp_implementation
temporal40ee5512008-07-10 02:12:20 +0000109
110 This step may require superuser privileges.
Josh Haberman2bd813b2015-04-09 16:41:58 -0700111 NOTE: To use C++ implementation, you need to export an environment
112 variable before running your program. See the "C++ Implementation"
113 section below for more details.
temporal40ee5512008-07-10 02:12:20 +0000114
115Usage
116=====
117
118The complete documentation for Protocol Buffers is available via the
119web at:
120
Feng Xiaoe4288622014-10-01 16:26:23 -0700121 https://developers.google.com/protocol-buffers/
[email protected]9b7f6c52010-12-08 03:45:27 +0000122
123C++ Implementation
124==================
125
[email protected]9b7f6c52010-12-08 03:45:27 +0000126The C++ implementation for Python messages is built as a Python extension to
127improve the overall protobuf Python performance.
128
Manjunath Kudlurcf828de2016-03-25 10:58:46 -0700129To use the C++ implementation, you need to install the C++ protobuf runtime
130library, please see instructions in the parent directory.