I want a intellisense of protobuf class generated in python. But the implementation of generated protobuf class are special, the code is like:
class X(_message.Message):
__metaclass__ = _reflection.GeneratedProtocolMessageType
DESCRIPTOR = _X
Most python IDE only can intellisense __metaclass__
and DESCRIPTOR
two members rather than the members defined in .proto file.
How to make it?
Protocol buffers (Protobuf) are a language-agnostic data serialization format developed by Google. Protobuf is great for the following reasons: Low data volume: Protobuf makes use of a binary format, which is more compact than other formats such as JSON. Persistence: Protobuf serialization is backward-compatible.
If you cannot open your PROTO file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a PROTO file directly in the browser: Just drag the file onto this browser window and drop it.
If you're using a recent Python version (3.7+) then you can try out my https://github.com/danielgtaylor/python-betterproto project. It generates dataclasses with proper types that VSCode, PyCharm, and others can use to provide type hints & intellisense.
For example, given this input:
syntax = "proto3";
// Some documentation about the Test message.
message Test {
// Some documentation about the count.
int32 count = 1;
}
You would get output like this:
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: int32.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
@dataclass
class Test(betterproto.Message):
"""Some documentation about the Test message."""
# Some documentation about the count.
count: int = betterproto.int32_field(1)
It is much, much easier to read than the official generated descriptor classes.
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