{"library":"nanopb","title":"Nanopb Protocol Buffers Generator","description":"Nanopb is a small code-size Protocol Buffers implementation in ANSI C, primarily suitable for microcontrollers and other memory-restricted systems. The Python library component provides the `nanopb_generator.py` script, which compiles `.proto` definition files into C header (`.h`) and source (`.c`) files that can then be used with the Nanopb C runtime. The project is actively maintained, with versions typically released a few times a year, addressing bug fixes and minor improvements, such as the latest 0.4.9.1 release from December 2024.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install nanopb","pip install --upgrade protobuf grpcio-tools"],"cli":{"name":"nanopb_generator.py","version":"sh: 1: nanopb_generator.py: not found"}},"imports":["python -m nanopb.generator.nanopb_generator your_message.proto"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"# 1. Define your Protocol Buffer message in a .proto file (e.g., example.proto):\n# message SimpleMessage {\n#   required int32 value = 1;\n# }\n\n# 2. Run the nanopb generator script:\nimport subprocess\nimport os\n\nproto_content = \"\"\"\nsyntax = \"proto2\";\n\nmessage SimpleMessage {\n  required int32 value = 1;\n}\n\"\"\"\n\nwith open(\"example.proto\", \"w\") as f:\n    f.write(proto_content)\n\n# Ensure protobuf and grpcio-tools are installed\ntry:\n    import google.protobuf\n    print(\"google.protobuf module found.\")\nexcept ImportError:\n    print(\"google.protobuf not found. Please install with: pip install protobuf grpcio-tools\")\n    exit(1)\n\n# Specify the path to the generator script\n# In an installed package, it's usually found via -m\ngenerator_path = \"nanopb.generator.nanopb_generator\"\n\nprint(f\"Generating C files from example.proto using {generator_path}...\")\ntry:\n    # Using python -m for installed package\n    result = subprocess.run(\n        [\"python\", \"-m\", generator_path, \"example.proto\"],\n        capture_output=True, text=True, check=True\n    )\n    print(\"STDOUT:\", result.stdout)\n    print(\"STDERR:\", result.stderr)\n    print(\"Successfully generated example.pb.h and example.pb.c\")\n\n    # Verify output files exist (optional)\n    if os.path.exists(\"example.pb.h\") and os.path.exists(\"example.pb.c\"):\n        print(\"Output files example.pb.h and example.pb.c found.\")\n    else:\n        print(\"Error: Generated files not found.\")\n\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error during generation: {e}\")\n    print(\"STDOUT:\", e.stdout)\n    print(\"STDERR:\", e.stderr)\n    print(\"Make sure 'protoc' is available in your PATH or installed via grpcio-tools.\")\nexcept FileNotFoundError as e:\n    print(f\"Error: Python or the generator script was not found. {e}\")\n\n# Clean up generated files\n# os.remove(\"example.proto\")\n# if os.path.exists(\"example.pb.h\"): os.remove(\"example.pb.h\")\n# if os.path.exists(\"example.pb.c\"): os.remove(\"example.pb.c\")","lang":"python","description":"This quickstart demonstrates how to define a simple Protocol Buffer message and then use the `nanopb_generator.py` script to generate the corresponding C header and source files for use with the Nanopb C runtime. It assumes `nanopb`, `protobuf`, and `grpcio-tools` are already installed.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"0.4.9.1","pypi_latest":"0.4.9.1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":3,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"111.1M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"19.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":4.4,"import_time_s":null,"mem_mb":null,"disk_size":"176M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.1,"import_time_s":null,"mem_mb":null,"disk_size":"21M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"118.0M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"22.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.5,"import_time_s":null,"mem_mb":null,"disk_size":"183M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2,"import_time_s":null,"mem_mb":null,"disk_size":"23M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"118.6M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"14.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.4,"import_time_s":null,"mem_mb":null,"disk_size":"183M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.8,"import_time_s":null,"mem_mb":null,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"115.2M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"13.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.6,"import_time_s":null,"mem_mb":null,"disk_size":"182M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.8,"import_time_s":null,"mem_mb":null,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"110.1M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"19.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":5.3,"import_time_s":null,"mem_mb":null,"disk_size":"175M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"nanopb","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.3,"import_time_s":null,"mem_mb":null,"disk_size":"20M"}]}}