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 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 4 | Copyright 2008 Google Inc. |
| 5 | |
| 6 | This directory contains the Python Protocol Buffers runtime library. |
| 7 | |
temporal | cc93043 | 2008-07-21 20:28:30 +0000 | [diff] [blame] | 8 | Normally, this directory comes as part of the protobuf package, available |
| 9 | from: |
| 10 | |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 11 | https://developers.google.com/protocol-buffers/ |
temporal | cc93043 | 2008-07-21 20:28:30 +0000 | [diff] [blame] | 12 | |
| 13 | The complete package includes the C++ source code, which includes the |
| 14 | Protocol Compiler (protoc). If you downloaded this package from PyPI |
| 15 | or some other Python-specific source, you may have received only the |
| 16 | Python part of the code. In this case, you will need to obtain the |
| 17 | Protocol Compiler from some other source before you can use this |
| 18 | package. |
| 19 | |
temporal | 742e409 | 2008-08-27 19:25:48 +0000 | [diff] [blame] | 20 | Development Warning |
| 21 | =================== |
| 22 | |
Peter Newman | e2cc2de | 2020-08-10 19:08:25 +0100 | [diff] [blame] | 23 | The pure python performance is slow. For better performance please |
Jie Luo | dec4939 | 2020-03-25 15:59:46 -0700 | [diff] [blame] | 24 | use python c++ implementation. |
temporal | 742e409 | 2008-08-27 19:25:48 +0000 | [diff] [blame] | 25 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 26 | Installation |
| 27 | ============ |
| 28 | |
Joshua Haberman | 301d315 | 2022-02-08 18:31:50 -0800 | [diff] [blame] | 29 | 1) Make sure you have Python 3.7 or newer. If in doubt, run: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 30 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 31 | $ python -V |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 32 | |
| 33 | 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] | 34 | downloaded and installed automatically as soon as you run `setup.py`. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 35 | 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] | 36 | 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] | 37 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 38 | 3) Build the C++ code, or install a binary distribution of `protoc`. If |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 39 | you install a binary distribution, make sure that it is the same |
| 40 | version as this package. If in doubt, run: |
| 41 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 42 | $ protoc --version |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 43 | |
[email protected] | a36f1b4 | 2013-02-26 17:49:03 +0000 | [diff] [blame] | 44 | 4) Build and run the tests: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 45 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 46 | $ python setup.py build |
| 47 | $ python setup.py test |
[email protected] | 1eba9d9 | 2014-08-25 20:17:53 +0000 | [diff] [blame] | 48 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 49 | To build, test, and use the C++ implementation, you must first compile |
| 50 | `libprotobuf.so`: |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 51 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 52 | $ (cd .. && make) |
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 | On OS X: |
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 | 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 Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 60 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 61 | You can either unlink Homebrew's protobuf or install the `libprotobuf` you |
| 62 | built earlier: |
Tamir Duberstein | d632bc7 | 2015-04-10 15:26:58 -0400 | [diff] [blame] | 63 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 64 | $ brew unlink protobuf |
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 | or |
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 | $ (cd .. && make install) |
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 | On other *nix: |
Josh Haberman | 2bd813b | 2015-04-09 16:41:58 -0700 | [diff] [blame] | 71 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 72 | 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 |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 88 | |
| 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 Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 94 | 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 Hunter | 130bb07 | 2016-11-16 17:34:28 +0000 | [diff] [blame] | 98 | 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] | 99 | how likely it is that this bug will affect users in practice. |
| 100 | |
| 101 | 5) Install: |
| 102 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 103 | $ python setup.py install |
jesse | cd04e9b | 2015-03-16 15:15:59 -0700 | [diff] [blame] | 104 | |
Misha Brukman | 6775570 | 2017-05-23 10:33:03 -0400 | [diff] [blame] | 105 | or: |
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 | $ (cd .. && make install) |
| 108 | $ python setup.py install --cpp_implementation |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 109 | |
| 110 | This step may require superuser privileges. |
Josh Haberman | 2bd813b | 2015-04-09 16:41:58 -0700 | [diff] [blame] | 111 | 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. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 114 | |
| 115 | Usage |
| 116 | ===== |
| 117 | |
| 118 | The complete documentation for Protocol Buffers is available via the |
| 119 | web at: |
| 120 | |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 121 | https://developers.google.com/protocol-buffers/ |
[email protected] | 9b7f6c5 | 2010-12-08 03:45:27 +0000 | [diff] [blame] | 122 | |
| 123 | C++ Implementation |
| 124 | ================== |
| 125 | |
[email protected] | 9b7f6c5 | 2010-12-08 03:45:27 +0000 | [diff] [blame] | 126 | The C++ implementation for Python messages is built as a Python extension to |
| 127 | improve the overall protobuf Python performance. |
| 128 | |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 129 | To use the C++ implementation, you need to install the C++ protobuf runtime |
| 130 | library, please see instructions in the parent directory. |