This Python package provides a convenient wrapper to install the `protoc-gen-openapiv2` binary. The binary generates OpenAPI v2 (Swagger) definitions directly from Protocol Buffer service definitions, making it a critical component for gRPC Gateway projects to expose gRPC services as RESTful APIs. It is currently at version 0.0.1, with development closely tied to the upstream Go project.
pip install protoc-gen-openapiv2No compatibility data collected yet for this library.
This quickstart demonstrates how to use the `protoc-gen-openapiv2` plugin via a Python script. It creates a dummy `.proto` file, then executes the `protoc` command to generate an OpenAPI v2 specification. This highlights that the package primarily provides a command-line tool, not Python symbols for direct import. Ensure `protoc` is installed and `protoc-gen-openapiv2` is in your system's PATH.
Always interact with `protoc-gen-openapiv2` through the `protoc` command-line tool, typically within a build script or Makefile. Do not expect to `import protoc_gen_openapiv2` in your Python application code.
Install `protoc` separately. For example, on Debian/Ubuntu: `sudo apt install protobuf-compiler`. For other systems, refer to the official Protocol Buffers documentation.
Ensure the directory where `pip` installs binaries is included in your system's PATH environment variable. Alternatively, call the binary using its full path.
Verify that all directories containing `.proto` files are correctly added to the `protoc` command with `-I` flags. For `google/api/annotations.proto`, you might need to clone the `grpc-ecosystem/grpc-gateway` repository and include its `third_party/googleapis` directory.
Pin your `protoc-gen-openapiv2` version in your `requirements.txt` or build environment to avoid unexpected breakage. Thoroughly test when upgrading to new versions.
Ensure the `protoc-gen-openapiv2` Python package is installed via `pip install protoc-gen-openapiv2`, which downloads the binary. Then, verify that the directory containing the installed binary (e.g., `~/.local/bin` or a Python virtual environment's `bin` directory) is included in your system's PATH environment variable. You might also need to explicitly `chmod +x` the binary if it has permission issues. If installing manually (without the Python wrapper), use `go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest` and ensure `$GOPATH/bin` is in your PATH.
You need to provide the `protoc` compiler with the correct path to the `annotations.proto` and `openapiv2.proto` files. These files are usually located within the `protoc-gen-openapiv2/options` directory of the `grpc-gateway` repository. The Python package `protoc-gen-openapiv2` makes these available. You should include the directory containing the `protoc-gen-openapiv2/options` folder in your `protoc` command using the `-I` flag. For example, if you've copied these files to a `third_party/googleapis` directory in your project, your command might look like `protoc -I. -I./third_party/googleapis --openapiv2_out=. your_service.proto`.
If you intend to install the `protoc-gen-openapiv2` binary as a global tool (and not as a dependency of a specific Go module), use `go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest`. This command should work outside of a Go module. If you are developing a Go project and want to manage it as a module dependency, ensure you are in a directory with a `go.mod` file (created with `go mod init <your_module_path>`). For this specific Python wrapper library, consider using `pip install protoc-gen-openapiv2` as the recommended way to get the binary, which abstracts away Go-specific installation details.
Add the directory containing the binary (e.g., `~/.local/bin` after `pip install`) to your system's `PATH`, or ensure your Python environment's `bin` directory is sourced. For convenience, running `python -m protoc_gen_openapiv2.install` often prints the binary's full path.
Download or clone the `googleapis` repository (e.g., `github.com/googleapis/googleapis`) and provide its root directory to `protoc` using the `-I` flag; for example: `protoc -I. -I/path/to/googleapis ...`.
No dependency data recorded yet.