Skip to main content

Python dataclasses for the Envoy Data-Plane-API

Project description

envoy_data_plane

A conversion of envoyproxy/data-plane-api protocol buffers into Python dataclasses using betterproto

Intended usage

This is a helper library that allows importing every type available in the envoy API.

One use-case might be generating Envoy configuration using a Python script.

In my case, I will use this library in my custom built control-plane, so that I have autocompletion in my IDE, and a basic form of validation.

In future, this may also help with building an idiomatic GRPC control-plane in Python.

Installation

This package is published to PyPI:

python -m pip install envoy_data_plane

Installing specific XDS revisions

There are branches available with compiled python protobuf files.
To install them, you can use the following syntax:

pip install git+https://github.com/cetanu/envoy_data_plane@<BRANCH NAME>

Examples:

pip install git+https://github.com/cetanu/envoy_data_plane@envoy_v1.13.7
pip install git+https://github.com/cetanu/envoy_data_plane@envoy_v1.16.2
pip install git+https://github.com/cetanu/envoy_data_plane@envoy_v1.17.2
pip install git+https://github.com/cetanu/envoy_data_plane@envoy_v1.18.2
pip install git+https://github.com/cetanu/envoy_data_plane@envoy_v1.19.0

Not all versions may be available. Raise an issue if you need another one added.

Example

import stringcase
import json
import envoy_data_plane.envoy.api.v2 as envoy

route_config = envoy.RouteConfiguration(
    name='MyRouteConfig',
    virtual_hosts=[
        envoy.route.VirtualHost(
            name='SomeWebsite',
            domains=['foobar.com'],
            routes=[
                envoy.route.Route(
                    name='catchall',
                    match=envoy.route.RouteMatch(
                        prefix='/'
                    ),
                    direct_response=envoy.route.DirectResponseAction(
                        status=200,
                        body=envoy.core.DataSource(
                            inline_string='Hello there'
                        )
                    )
                )
            ]
        )
    ]
)

response = envoy.DiscoveryResponse(
    version_info='0',
    resources=[
        route_config
    ],
)

print(
    json.dumps(response.to_dict(casing=stringcase.snakecase), indent=2)
)

Result:

{
  "version_info": "0",
  "resources": [
    {
      "name": "MyRouteConfig",
      "virtual_hosts": [
        {
          "name": "SomeWebsite",
          "domains": [
            "foobar.com"
          ],
          "routes": [
            {
              "name": "catchall",
              "match": {
                "prefix": "/",
                "headers": [],
                "query_parameters": []
              },
              "direct_response": {
                "status": 200,
                "body": {
                  "inline_string": "Hello there"
                }
              },
              "request_headers_to_add": [],
              "response_headers_to_add": []
            }
          ],
          "virtual_clusters": [],
          "rate_limits": [],
          "request_headers_to_add": [],
          "response_headers_to_add": []
        }
      ],
      "response_headers_to_add": [],
      "request_headers_to_add": []
    }
  ]
}

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

envoy_data_plane-0.8.1.tar.gz (590.3 kB view details)

Uploaded Source

Built Distribution

envoy_data_plane-0.8.1-py3-none-any.whl (937.7 kB view details)

Uploaded Python 3

File details

Details for the file envoy_data_plane-0.8.1.tar.gz.

File metadata

  • Download URL: envoy_data_plane-0.8.1.tar.gz
  • Upload date:
  • Size: 590.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure

File hashes

Hashes for envoy_data_plane-0.8.1.tar.gz
Algorithm Hash digest
SHA256 366ce025c035ea6f9f306b7c3cd3a7072db546fab1d6fb98202e8532354cd0cf
MD5 67855ae398ba9101c83eb43836d2a850
BLAKE2b-256 69fe29195b48174f90135361215bd1c9bb8099fb26160ccaefd8843025404920

See more details on using hashes here.

File details

Details for the file envoy_data_plane-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: envoy_data_plane-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 937.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure

File hashes

Hashes for envoy_data_plane-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8a64196124c4bf5ede3455b946142b88283db5bf77ef69d51e9ad6d2a7a2ad7
MD5 ba78acbcf4b1af71ac839c7761c9841d
BLAKE2b-256 9edf1bca1d25c0b2d95dd67b2ecd1e16c533ffb0c73fec97db800db9d31673af

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