Live data from Hacker News

Protobuf-py: Protobuf for Python, without compromises

buf.build

31–40 of 65 posts

Re: Protobuf-py: Protobuf for Python, without compromises

#31

Optimizing for the last microsecond and then use Python? Why?

Are the only two options SIMD in hand-rolled assembler and unbearably slow?

Often Python, with the most critical parts written in a compiled extension module (like this one), offers acceptable performance with enormously less complexity than writing the whole thing in a compiled language.

Re: Protobuf-py: Protobuf for Python, without compromises

#32

Slightly off topic, but is anyone aware of a compile free method to convert protobuf messages to json representation based on a provided .proto file (and the other way around)? All protobuf implementations seem to require a compilation step, which makes it hard to support en-/decoding untrusted content using user provided schemas

[dead]

Re: Protobuf-py: Protobuf for Python, without compromises

#33
post #23

Engineer who works on Google Protobuf here, commenting as myself and not as an official statement. It's great to have a healthy ecosystem in the world around Protobuf. Google can't possibly fill all use cases, there's many tools and Buf makes good tooling. The Protobuf team at Google intentionally tries to enable an ecosystem around Protobuf including examples like this. Google Cloud APIs are intentionally usable wit…

> ... that uses C++Proto as the in memory representation which libraries like TensorFlow can use to share memory between Python and C++

This is a valid explanation for the odd implementation of the Python protobuf library (the only convincing one I've heard). But, the last time I looked into it (just a couple of years ago), it didn't seem reasonably possible to make use of this.

I can't remember the exact issue I think maybe the C++ library would be statically linked into the Python C extension module, which made it virtually impossible to use it from your own C++ code. Or maybe the issue was just that there was no C++ version prebuilt on pypi (the default is the upb version).

Anyway, it seems a pity to go to such enormous lengths for one feature and then make it essentially unavailable.

Re: Protobuf-py: Protobuf for Python, without compromises

#34

This is incredible news! I’ve used protobuf in Python, Go, Kotlin and Dart and the Python implementation is totally unusable. I don’t know what black magic Google uses for the Python implementation, but the classes it generates are totally opaque and impossible to inspect. I’ve been waiting for a proper python implementation for years now!

> I don’t know what black magic Google uses for the Python implementation, but the classes it generates are totally opaque and impossible to inspect. TFA seems to say that they’re just thin proxies over the underlying C++ APIs, which would more than do it, and does not surprise me (the re2 Python bindings are similar, not as bad since they don’t generate Python code but they’re really c++-y — in Google’s flavour too…

I did not know this before... Google protobuf is not one thing, it is three! Same import, but:

* old C++ extension

* upb

* pure Python

upb parses FAST, but then every access is still C->Python and it slows it down. So for many reads the slow python one can win?

This one helped me to dig deeper - https://vectree.io/c/how-python-protobuf-runtimes-work-pure-...

Re: Protobuf-py: Protobuf for Python, without compromises

#36
Need something for backward compatible RPC? Use protobuf. But for storage and types?

This is where I feel there are better alternatives. If you go with protobuf, you're picking 2 out of 3: simplicity, fast, idiomatic.

Please consider "uvx tsc-py --help" for things that don't fit.

Re: Protobuf-py: Protobuf for Python, without compromises

#37
post #8

Earlier quoted context omitted.

Hey. I wrote another Python implementation of Protobuf. (protopy https://gitlab.com/doodles-archive/protopy it was a while ago and haven't touched it since). I'm not saying it's better than whatever this is or that it's any good, I just post it as a proof of sorts that I'm familiar with the problem. So, without further ado: Protobuf isn't a standard. You can't have a non-standard implementation of something that does…

> I just think that Protobuf is not a good format for writing reliable software that aims for decades of usage. I am not a fan of Protobuf at all, but it's already demonstrated its ability to ship extremely reliable software with multi-decade lifespans. It's one of the few things Google _hasn't_ deprecated, and it's the backbone of the search and ads stack.

I don't know what your metric for reliability is... but I would say that the messaging / serialization format can hardly be blamed for reliability problems s.a. service uptime or service responsiveness etc. Such problems usually arise at a level where details like the choice of messaging format are not important.

Messaging format may affect application performance though. It would affect metrics s.a. throughput or bandwidth.

In a way that is more difficult to measure, a messaging format can affect the number of bugs created by developer using it and indirectly the delivery times. But this can be mitigated by tooling (i.e. Protobuf isn't self-documenting, so if you don't have the schema files, you can't interpret the messages, but you can write a tool that you can feed the schema definitions and then use the tool to interpret the messages).

> It's one of the few things Google _hasn't_ deprecated

You might be unaware of it, but there were Protobuf v1, v2, and now we are at v3. Even though it's not documented, v3 supports most of v2, but not all of it (I think v1 was never used outside of Google itself). Google never properly released Protobuf, so, they can't really deprecate it. Even their formal grammar is full of errors.

Re: Protobuf-py: Protobuf for Python, without compromises

#38

Need something for backward compatible RPC? Use protobuf. But for storage and types? This is where I feel there are better alternatives. If you go with protobuf, you're picking 2 out of 3: simplicity, fast, idiomatic. Please consider "uvx tsc-py --help" for things that don't fit.

Just in case you find the earlier message too cryptic. It's not performing well on web search.

https://pypi.org/project/tsc-py/

Re: Protobuf-py: Protobuf for Python, without compromises

#39
post #16
post #8

Earlier quoted context omitted.

Hey. I wrote another Python implementation of Protobuf. (protopy https://gitlab.com/doodles-archive/protopy it was a while ago and haven't touched it since). I'm not saying it's better than whatever this is or that it's any good, I just post it as a proof of sorts that I'm familiar with the problem. So, without further ado: Protobuf isn't a standard. You can't have a non-standard implementation of something that does…

Why does it matter for some Python implementation if the Google C++ implementation has a lazy or eager parser? The important part of protobuf is the spec of the wire format. That is what makes the standard an interop format. Personally I also prefer code generation over dynamic parsers and generators. This is not an idiosyncrasy of C++, it is just the objectively good way to handle IDLs regardless of programming lang…

> Why does it matter for some Python implementation if the Google C++ implementation has a lazy or eager parser?

I wrote about it in my repository, but I'll try to summarize it here: Protobuf is full of bad ideas. One such bad idea is that message fields are allowed to repeat and that the last field wins. So, if you were to write a SAX parser, you'd have a dilemma with how to handle this bizarre idea: do you accept that a callback for some property might be triggered multiple times or do you read the whole message ahead of time and then call callbacks exactly once for each property? If we accept that the parser must be lazy, we "solve" this problem by allowing the parser to read ahead (it needs to do this anyways), but this is a wasteful way to parse (uses more memory than necessary).

> The important part of protobuf is the spec of the wire format. That is what makes the standard an interop format.

I'm not sure what are you trying to say here. All messaging formats are made up of... wire format, that's what they are for. Maybe I'm not seeing it?

> Personally I also prefer code generation over dynamic parsers and generators.

I think you are trying to say that you prefer source code generation over generating supporting definitions at runtime? I wasn't talking about dynamic parser generation (eg. Lark). In my case, the parser was hand-written (using Bison + Flex) and compiled ahead of time, but the Python definitions supporting the Protobuf IML were generated at runtime.

If my guess is true, I'd like to hear your arguments in favor of generating Python source code that translates Protobuf IML into Python. To me it looks like a waste of space on disk... I really can't think of any reason to want that.

Re: Protobuf-py: Protobuf for Python, without compromises

#40
post #11
post #8

Earlier quoted context omitted.

Hey. I wrote another Python implementation of Protobuf. (protopy https://gitlab.com/doodles-archive/protopy it was a while ago and haven't touched it since). I'm not saying it's better than whatever this is or that it's any good, I just post it as a proof of sorts that I'm familiar with the problem. So, without further ado: Protobuf isn't a standard. You can't have a non-standard implementation of something that does…

At least, Google has the resources and the will to support all their implementations in the long run. I don't always agree with what they do there, but at least I can be sure that it will still work ten years from now. At some point it becomes more important than implementation details

I don't know where you get the confidence... When it comes to Protobuf, we are now at version 3 of the format. It's been around for a while, but I'm old enough to have implemented v2 parser myself... v2 is partially supported in v3, even though the support isn't documented. But, emphasis on partially. Some things are no longer there.

So... I'd say that your faith is unfounded. And, in general, there's no reason to believe that a commercial entity will commit to supporting any particular technology if that doesn't generate them a profit. Standard is better.

Post reply on HN