temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 1 | Protocol Buffers - Google's data interchange format |
jesse | cd04e9b | 2015-03-16 15:15:59 -0700 | [diff] [blame] | 2 | =================================================== |
| 3 | |
Lily Li | a1b3d5e | 2019-06-06 17:30:50 -0700 | [diff] [blame] | 4 | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython%2Fcontinuous) [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_compatibility%2Fcontinuous) [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_cpp%2Fcontinuous) [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython%2Fcontinuous) [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython_cpp%2Fcontinuous) [](https://python-compatibility-tools.appspot.com/one_badge_target?package=protobuf) |
jesse | cd04e9b | 2015-03-16 15:15:59 -0700 | [diff] [blame] | 5 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 6 | Copyright 2008 Google Inc. |
| 7 | |
| 8 | This directory contains the Python Protocol Buffers runtime library. |
| 9 | |
temporal | cc93043 | 2008-07-21 20:28:30 +0000 | [diff] [blame] | 10 | Normally, this directory comes as part of the protobuf package, available |
| 11 | from: |
| 12 | |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 13 | https://developers.google.com/protocol-buffers/ |
temporal | cc93043 | 2008-07-21 20:28:30 +0000 | [diff] [blame] | 14 | |
| 15 | The complete package includes the C++ source code, which includes the |
| 16 | Protocol Compiler (protoc). If you downloaded this package from PyPI |
| 17 | or some other Python-specific source, you may have received only the |
| 18 | Python part of the code. In this case, you will need to obtain the |
| 19 | Protocol Compiler from some other source before you can use this |
| 20 | package. |
| 21 | |
temporal | 742e409 | 2008-08-27 19:25:48 +0000 | [diff] [blame] | 22 | Development Warning |
| 23 | =================== |
| 24 | |
Jie Luo | dec4939 | 2020-03-25 15:59:46 -0700 | [diff] [blame] | 25 | The pure python performance is slow. For better preformance please |
| 26 | use python c++ implementation. |
temporal | 742e409 | 2008-08-27 19:25:48 +0000 | [diff] [blame] | 27 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 28 | Installation |
| 29 | ============ |
| 30 | |
Yuchen Xie | 595231d | 2018-06-26 06:20:53 +0800 | [diff] [blame] | 31 | 1) Make sure you have Python 2.7 or newer. If in doubt, run: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 32 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 33 | $ python -V |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 34 | |
| 35 | 2) If you do not have setuptools installed, note that it will be |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 36 | downloaded and installed automatically as soon as you run `setup.py`. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 37 | If you would rather install it manually, you may do so by following |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 38 | the instructions on [this page](https://packaging.python.org/en/latest/installing.html#setup-for-installing-packages). |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 39 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 40 | 3) Build the C++ code, or install a binary distribution of `protoc`. If |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 41 | you install a binary distribution, make sure that it is the same |
| 42 | version as this package. If in doubt, run: |
| 43 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 44 | $ protoc --version |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 45 | |
xiaofeng@google.com | a36f1b4 | 2013-02-26 17:49:03 +0000 | [diff] [blame] | 46 | 4) Build and run the tests: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 47 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 48 | $ python setup.py build |
| 49 | $ python setup.py test |
jieluo@google.com | 1eba9d9 | 2014-08-25 20:17:53 +0000 | [diff] [blame] | 50 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 51 | To build, test, and use the C++ implementation, you must first compile |
| 52 | `libprotobuf.so`: |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 53 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 54 | $ (cd .. && make) |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 55 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 56 | On OS X: |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 57 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 58 | If you are running a Homebrew-provided Python, you must make sure another |
| 59 | version of protobuf is not already installed, as Homebrew's Python will |
| 60 | search `/usr/local/lib` for `libprotobuf.so` before it searches |
| 61 | `../src/.libs`. |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 62 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 63 | You can either unlink Homebrew's protobuf or install the `libprotobuf` you |
| 64 | built earlier: |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 65 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 66 | $ brew unlink protobuf |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 67 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 68 | or |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 69 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 70 | $ (cd .. && make install) |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 71 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 72 | On other *nix: |
Josh Haberman | 2bd813b | 2015-04-09 16:41:58 -0700 | [diff] [blame] | 73 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 74 | You must make `libprotobuf.so` dynamically available. You can either |
| 75 | install libprotobuf you built earlier, or set `LD_LIBRARY_PATH`: |
| 76 | |
| 77 | $ export LD_LIBRARY_PATH=../src/.libs |
| 78 | |
| 79 | or |
| 80 | |
| 81 | $ (cd .. && make install) |
| 82 | |
| 83 | To build the C++ implementation run: |
| 84 | |
| 85 | $ python setup.py build --cpp_implementation |
| 86 | |
| 87 | Then run the tests like so: |
| 88 | |
| 89 | $ python setup.py test --cpp_implementation |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 90 | |
| 91 | If some tests fail, this library may not work correctly on your |
| 92 | system. Continue at your own risk. |
| 93 | |
| 94 | Please note that there is a known problem with some versions of |
| 95 | Python on Cygwin which causes the tests to fail after printing the |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 96 | error: `sem_init: Resource temporarily unavailable`. This appears |
| 97 | to be a [bug either in Cygwin or in |
| 98 | Python](http://www.cygwin.com/ml/cygwin/2005-07/msg01378.html). |
| 99 | |
Ian Hunter | 130bb07 | 2016-11-16 17:34:28 +0000 | [diff] [blame] | 100 | We do not know if or when it might be fixed. We also do not know |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 101 | how likely it is that this bug will affect users in practice. |
| 102 | |
| 103 | 5) Install: |
| 104 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 105 | $ python setup.py install |
jesse | cd04e9b | 2015-03-16 15:15:59 -0700 | [diff] [blame] | 106 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 107 | or: |
jesse | cd04e9b | 2015-03-16 15:15:59 -0700 | [diff] [blame] | 108 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 109 | $ (cd .. && make install) |
| 110 | $ python setup.py install --cpp_implementation |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 111 | |
| 112 | This step may require superuser privileges. |
Josh Haberman | 2bd813b | 2015-04-09 16:41:58 -0700 | [diff] [blame] | 113 | NOTE: To use C++ implementation, you need to export an environment |
| 114 | variable before running your program. See the "C++ Implementation" |
| 115 | section below for more details. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 116 | |
| 117 | Usage |
| 118 | ===== |
| 119 | |
| 120 | The complete documentation for Protocol Buffers is available via the |
| 121 | web at: |
| 122 | |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 123 | https://developers.google.com/protocol-buffers/ |
liujisi@google.com | 9b7f6c5 | 2010-12-08 03:45:27 +0000 | [diff] [blame] | 124 | |
| 125 | C++ Implementation |
| 126 | ================== |
| 127 | |
liujisi@google.com | 9b7f6c5 | 2010-12-08 03:45:27 +0000 | [diff] [blame] | 128 | The C++ implementation for Python messages is built as a Python extension to |
| 129 | improve the overall protobuf Python performance. |
| 130 | |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 131 | To use the C++ implementation, you need to install the C++ protobuf runtime |
| 132 | library, please see instructions in the parent directory. |