plugins icon indicating copy to clipboard operation
plugins copied to clipboard

Plugin request for Buf Schema Registry: protobuf_to_pydantic

Open cfstras opened this issue 1 year ago • 10 comments

Mandatory

Where is the source code for the plugin?

https://github.com/so1n/protobuf_to_pydantic

Optional

Does the plugin have a valid semver version?

Latest: https://github.com/so1n/protobuf_to_pydantic/releases/tag/v0.1.7

Does the plugin have a dependency on another plugin?

I don't think so, but it has runtime dependencies: https://github.com/so1n/protobuf_to_pydantic/blob/master/requirements-no-grpc.txt

Does the output of this plugin depend on any other external libraries?

The output depends on the python library pydantic: https://docs.pydantic.dev/latest/

cfstras avatar Jun 16 '23 12:06 cfstras

Seconding this as a feature request!

dwwhitlock avatar Oct 25 '23 19:10 dwwhitlock

I'm not sure this will work as a Remote Plugin. Browsing around the linked repository, there are two potential issues:

  1. This code reads a config file from the filesystem, this isn't something we support.

https://github.com/so1n/protobuf_to_pydantic/blob/fdab3a37f63d5436b0095a62e9f1a039ca458640/protobuf_to_pydantic/plugin/code_gen.py#L49

  1. I don't see where it implements the CodeGeneratorRequest on stdin. Is this a typical protoc-gen- plugin?

Can this plugin be used with protoc or buf locally? Could you provide an example how you'd use it with one of the tools I mentioned?

mfridman avatar Oct 25 '23 21:10 mfridman

I've used this locally with buf, simply by installing it via pypoetry or pip, and specifying protobuf_to_pydantic as a plugin in a buf.gen.yml.

(For pypoetry, buf will have to be run through poetry run buf .

cfstras avatar Oct 26 '23 10:10 cfstras

~@cfstras can you provide the relevant snippet of your buf.gen.yaml?~ Local usage:

  - plugin: protobuf-to-pydantic
    out: ../python/src/pydantic
    

dwwhitlock avatar Oct 26 '23 15:10 dwwhitlock

For more context, integration with Pydantic will allow for proto use with FastAPI, which is the most widely used Python REST API framework. https://github.com/tiangolo/fastapi

dwwhitlock avatar Oct 26 '23 15:10 dwwhitlock

I've used this locally with buf, simply by installing it via pypoetry or pip, and specifying protobuf_to_pydantic as a plugin in a buf.gen.yml.

(For pypoetry, buf will have to be run through poetry run buf .

Okay, that's good to hear. Does it require any local state, like reading a config from your filesystem?

mfridman avatar Oct 26 '23 17:10 mfridman

The author of the source plugin (@so1n) said they are on board with implementing it https://github.com/so1n/protobuf_to_pydantic/issues/26

dwwhitlock avatar Oct 30 '23 14:10 dwwhitlock

@dwwhitlock based on the comment above

I've used this locally with buf, simply by installing it via pypoetry or pip, and specifying protobuf_to_pydantic as a plugin in a buf.gen.yml.

It sounds like this is a plugin that already works with buf or protoc, but I have not looked into that code deeply outside a cursory 30s scan.

My outstanding question is, does it require any local state, like reading a config or .proto files directly from the filesystem?

mfridman avatar Oct 30 '23 14:10 mfridman

It looks like it has an optional configuration .py file, which you mentioned would not be supported. That said, I also haven't looked deeply into it yet

dwwhitlock avatar Oct 30 '23 15:10 dwwhitlock

Hello, I am the author of this library. I've just finished implementing version 0.2.1, which enables protobuf-to-pydantic to run as a plugin for buf-cli (all feature of protobuf-to-pydantic works).The relevant description already exists in document. However, I found that I cannot upload public plugins to buf.build, I hope to get your help. @mfridman

so1n avatar Nov 07 '23 16:11 so1n