Skip to main content

A Python package for generating valid and invalid protobuf test data.

Project description

Protobuf Data Generator

PyPI Python Versions Build Status License

Overview

The Protobuf Data Generator creates realistic valid and invalid payloads for Protocol Buffer messages. It reads constraint annotations directly from your .proto files (for example, Protovalidate or Nanopb rules) and deterministically assembles data that either satisfies or intentionally violates those rules. The library is ideal for fuzzing, regression testing, and golden-data generation across embedded and backend protobuf workloads.

Features

  • Deterministic valid payloads generated from constraint metadata.
  • Targeted invalid samples that break explicit rules (e.g., min/max, length, uniqueness).
  • Constraint backends for Protovalidate and Nanopb, with a lightweight parser that understands enums and repeated fields.
  • Formatter outputs for C arrays, raw bytes, JSON, and hexadecimal encodings.
  • Showcase fixtures (tests/fixtures/showcase.proto) illustrating the full feature set end-to-end.

Installation

pip install protobuf-data-generator

For local development:

git clone https://github.com/OfekiAlm/protobuf-data-generator.git
cd protobuf-data-generator
pip install -r requirements-dev.txt

Usage

Python API

from protobuf_test_generator import DataGenerator

generator = DataGenerator(
		"tests/fixtures/showcase.proto",
		include_paths=["tests/fixtures"],
		constraints_type="protovalidate",  # or "nanopb"
)

valid_payload = generator.generate_valid("Showcase", seed=42)
invalid_payload = generator.generate_invalid(
		"Showcase",
		violate_field="email",
		violate_rule="min_len",
		seed=42,
)

binary_blob = generator.encode_to_binary("Showcase", valid_payload)
c_array = generator.format_output(binary_blob, "c_array", "showcase_payload")

Showcase workflow

  • tests/fixtures/showcase.proto – comprehensive proto covering numeric, string, enum, repeated, and nested-field constraints.
  • tests/test_showcase.py – integration test demonstrating parsing, generation, validation, and formatting steps.
  • The helper validate.proto shipped alongside the fixtures is a minimal stub replicating the option names used in the official protovalidate descriptors. It exists solely to exercise constraint parsing in tests.

Command line interface

python -m protobuf_test_generator \
	--proto_file tests/fixtures/showcase.proto \
	--message Showcase \
	--format json

Optional flags:

  • -I / --include path – repeatable include directories for proto imports.
  • --invalid --field FIELD --rule RULE – produce a payload that violates a specific rule.
  • --seed N – lock generation to deterministic output.

Development

black --check src tests
flake8 src tests
mypy src
pytest

See the CHANGELOG for release history.

Contributing

Issues and pull requests are welcome! Please discuss substantial changes in an issue before opening a PR.

License

Distributed under the MIT License. See LICENSE.

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

protobuf_data_generator-1.0.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

protobuf_data_generator-1.0.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file protobuf_data_generator-1.0.0.tar.gz.

File metadata

  • Download URL: protobuf_data_generator-1.0.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for protobuf_data_generator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bbd1de91e6bf2ae131dec86773728f8b98a95fde23aa9db96f2800972f666ce0
MD5 cd3d92c3d99ff0f33741c52f5ce20079
BLAKE2b-256 52cf762256777d9ea79346fc66d534e353b0069e4d8009c835752970af9fcf24

See more details on using hashes here.

File details

Details for the file protobuf_data_generator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for protobuf_data_generator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e236d5fba33d5f287762d51b54028247a6541b0945e74f984047c66870c8785
MD5 12d0aecc96171e58721ce5f0554f7a49
BLAKE2b-256 c1e1ff2802d0410c1f14b2a6f4ecebc62de3cb23b1a30811a86e97dbfcd0a162

See more details on using hashes here.

Supported by

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