Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin request for Buf Schema Registry: protobuf_to_pydantic #589

Open
cfstras opened this issue Jun 16, 2023 · 10 comments
Open

Plugin request for Buf Schema Registry: protobuf_to_pydantic #589

cfstras opened this issue Jun 16, 2023 · 10 comments
Labels
Feature New feature or request

Comments

@cfstras
Copy link

cfstras commented Jun 16, 2023

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 cfstras added the Feature New feature or request label Jun 16, 2023
@dwwhitlock
Copy link

Seconding this as a feature request!

@mfridman
Copy link
Member

mfridman commented Oct 25, 2023

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?

@cfstras
Copy link
Author

cfstras commented Oct 26, 2023

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 .

@dwwhitlock
Copy link

dwwhitlock commented Oct 26, 2023

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

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

@dwwhitlock
Copy link

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

@mfridman
Copy link
Member

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?

@dwwhitlock
Copy link

The author of the source plugin (@so1n) said they are on board with implementing it so1n/protobuf_to_pydantic#26

@mfridman
Copy link
Member

@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?

@dwwhitlock
Copy link

dwwhitlock commented Oct 30, 2023

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

@so1n
Copy link

so1n commented Nov 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants