python

package
v1.11.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package python implements the Python protobuf compiler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultExcludeImports added in v1.2.0

func DefaultExcludeImports() []string

DefaultExcludeImports returns the default list of module prefixes to exclude from import fixing These are well-known protobuf/grpc packages that come from external sources

func ValidateWorkDir added in v1.1.1

func ValidateWorkDir(workDir string) error

ValidateWorkDir validates that the workdir is a valid Python module path. A valid Python module path consists of dot-separated identifiers, where each identifier starts with a letter or underscore and contains only letters, digits, and underscores. Empty string is valid (no workdir prefix). Examples: "myapp", "my_project.api", "app123.module_name"

Types

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler implements the compiler.Compiler interface for Python

func New

func New(log *logger.Logger, opts *Options) *Compiler

New creates a new Python compiler

func (*Compiler) Compile

Compile compiles the given proto files to Python

func (*Compiler) GetOutputPath

func (c *Compiler) GetOutputPath(file compiler.ProtoFile, opts compiler.CompileOptions) string

GetOutputPath returns the output path for a proto file

func (*Compiler) Name

func (c *Compiler) Name() string

Name returns the compiler name

func (*Compiler) RequiredTools

func (c *Compiler) RequiredTools() []string

RequiredTools returns the list of required external tools

func (*Compiler) Validate

func (c *Compiler) Validate() error

Validate checks if the compiler is properly configured

type Options

type Options struct {
	// ProtocPath is the path to the protoc binary
	ProtocPath string

	// GrpcPythonPluginPath is the path to the grpc_python_plugin
	GrpcPythonPluginPath string

	// GenerateGrpc enables gRPC code generation
	GenerateGrpc bool

	// GenerateTyping enables .pyi stub file generation
	GenerateTyping bool

	// GenerateInit enables __init__.py generation
	GenerateInit bool

	// PythonPackagePrefix is the Python package prefix for imports
	PythonPackagePrefix string

	// WorkDir is the working directory prefix for imports (e.g., "myapp" -> "from myapp.generated.python import ...")
	WorkDir string

	// ExcludeImports is a list of module prefixes to exclude from import path fixing
	// These are typically external dependencies like google.protobuf, grpc, etc.
	ExcludeImports []string
}

Options contains Python-specific compilation options

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns default options for Python compiler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL