Skip to content

[Question] How to use protoc instead of buf in a python project  #237

@jmspereira

Description

@jmspereira

Hey everyone, sorry if this issue is duplicated, but I didn't find any that addressed the entire process or I am missing something when using protoc instead of buf. I have a python project with a set of protobuf files, I am compiling them with:

protoc <protobuf-files> 
-I/usr/local/include/protovalidate  
--fatal_warnings 
--python_out=/<outpath> 
--pyi_out=/<outpath>  
--include_imports 
--descriptor_set_out=<outpath>/gen

Where the include_imports and the descriptor_set_out were set as documented. However, even when I define the PYTHONPATH to the gen file, still does not work, with the following error:

>>> import protovalidate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/lib/python3.11/site-packages/protovalidate/__init__.py", line 15, in <module>
    from protovalidate import validator
  File "/venv/lib/python3.11/site-packages/protovalidate/validator.py", line 19, in <module>
    from buf.validate import expression_pb2  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'buf'

This is likely because this is not generating the validate_pb2.py but a binary file. So, what is the correct process in order to use protovalidate with protoc in a python project?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions