Skip to main content

Plugin for setuptools and grpc / protobuf python module build

Project description

PyPI - Version PyPI - License PyPI - Python Version GitHub Workflow Status (with event)

Plugin for setuptools to compile protobuf and gRPC service files to python modules.

This package provides build_grpc command for setuptools. Its purpose is to build gRPC modules during build step of setuptools packaging.

What this isn’t

This is not a command line script.

Direct invocation of setup.py (such as python setup.py build_grpc) has been deprecated and will be removed in future version of setuptools.

If you’d like to have CLI for building gRPC modules, use grpcio-tools directly (that’s what this package uses under the hood). After installing that package, you can learn about its options by running python -m grpc_tools.protoc --help.

Installation

You probably shouldn’t install this package directly. Instead, you should add it to the build-system.requires in pyproject.toml. See Configuration.

Options

Command build_grpc provides following options:

  • proto_files: Newline separated list of glob patterns matching protobuf files to be compiled. Paths are relative to the current directory. ** can be used to match any files and zero or more directories. Default value is empty list.

  • grpc_files: Newline separated list of glob patterns matching grpc service files to be compiled. Paths are relative to the current directory. ** can be used to match any files and zero or more directories. Default value is empty list.

  • proto_path: Path to root directory with protobuf files. This path is passed through -I option to grpc_tools.protoc. Default is . (current directory).

  • output_path: Path to root directory for generated python modules. This path is passed through --python_out or --grpc_python_out option to grpc_tools.protoc. Default is . (current directory).

Configuration

You have to specify setuptools-grpc as part of build backend requirements. This follows specification introduced in PEP 518. You can read more about it in setuptools docs.

# file: pyproject.toml
[build-system]
requires = ["setuptools", "setuptools-grpc"]
build-backend = "setuptools.build_meta"

Next, you need to actually add build_grpc as subcommand of the build command. This needs to be done in setup.py, but if setuptools ever allows for declarative config, we’ll be happy to support it.

# file: setup.py
from setuptools import setup
from setuptools.command.build import build

class custom_build(build):
    sub_commands = [
        ('build_grpc', None),
    ] + build.sub_commands

setup(cmdclass={'build': custom_build})

Finally, you need to configure setuptools_grpc itself. This can be done in setup.py, but we recommend declarative config in setup.cfg. Depending on your project structure, you may not need some of the options below. You’ll always need to specify at least proto_files or grpc_files, otherwise setuptools_grpc won’t do anything.

# file: setup.cfg
[build_grpc]
proto_files = src/**/*.proto
grpc_files = src/**/*_grpc.proto
proto_path = ./src
output_path = ./out

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-grpc-0.5.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

setuptools_grpc-0.5-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file setuptools-grpc-0.5.tar.gz.

File metadata

  • Download URL: setuptools-grpc-0.5.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for setuptools-grpc-0.5.tar.gz
Algorithm Hash digest
SHA256 0df3069952b424c0eabb17ee96c59ff751261f8398b58b3f8970e9dec5b25a47
MD5 09632ac735e75308c5fc726c78be60a8
BLAKE2b-256 639bef677f3a7e28b2ade809da3cc44c18a351f4bbfecb0c4809ec51db1d874c

See more details on using hashes here.

File details

Details for the file setuptools_grpc-0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for setuptools_grpc-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3c111d629b531ddf86e375891fbe8481f18538e4c05e9d631ad9e22632fb77e7
MD5 11f790e6b65f1a3b84d27d27cefacefc
BLAKE2b-256 cf2fd332a2265239ddb2a0a3fd4af2b5fd9eb862eba2d870c397562995605fa8

See more details on using hashes here.

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