Skip to main content

A modern setuptools plugin to generate Python files from proto files using betterproto

Project description

Betterproto Setuptools plugin

Build Status PyPI Package Docs

Introduction

A modern setuptools plugin to generate Python files from proto files using betterproto.

This plugin is based on repo-config's grpc_tools plugin.

Supported Platforms

The following platforms are officially supported (tested):

  • Python: 3.11
  • Operating System: Ubuntu Linux 20.04
  • Architectures: amd64, arm64

Quick Start

To add automatic betterproto code generation to your project, you need to add this package to your build-dependencies in the pyproject.toml file, for example:

[build-system]
requires = [
  "setuptools == 68.1.0",
  "setuptools-betterproto == 0.1.0",
]
build-backend = "setuptools.build_meta"

This uses a default configuration as follows:

  • proto_path: This is the root directory where the proto files are located. By default, it is set to ..
  • proto_glob: This is the glob pattern to match the proto files. The search is done recursively. By default, it is set to *.proto.
  • include_paths: This is a list of paths to be added to the protobuf compiler's include path. By default, it is set to [], but the proto_path directory is always automatically added.
  • out_path: This is the directory where the generated Python files will be placed. By default, it is set to ..

These defaults can be changed via the pypackage.toml file too. For example:

[tool.setuptools_betterproto]
proto_path = "proto"
include_paths = ["api-common-protos"]
out_dir = "src"

You should add betterproto as a dependency too, for example:

dependencies = ["betterproto == 2.0.0b6"]

Once this is done, the conversion of the proto files to Python files should be automatic. Just try building the package with:

python -m pip install build
python -m build

A new command to generate the files will be also added to setuptools, you can run it manually with:

python -c 'import setuptools; setuptools.setup()' compile_betterproto

You can also pass the configuration options via command line for quick testing, try passing --help at the end of the command to see the available options.

Contributing

If you want to know how to build this project and contribute to it, please check out the Contributing Guide.

Similar projects

  • setuptools-proto: We didn't use this project because it seems a bit inactive and not widely used. It also seems to need some configuration as code, which we wanted to avoid.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

setuptools-betterproto-0.2.0.tar.gz (11.5 kB view hashes)

Uploaded Source

Built Distribution

setuptools_betterproto-0.2.0-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page