title: Developer Guide

Overview

This documentation explains how to develop this project.

Prerequisites

  • Python 3.6+
  • APISIX 2.7.0

Debug

  • Run make setup Installation dependencies
  • Run export PYTHONPATH=$PYTHONPATH:/path/to/apisix-python-plugin-runner loading project path
  • Run APISIX_LISTEN_ADDRESS=unix:/tmp/runner.sock python3 apisix/main.py start to start it.

Plugin

Plugin directory

/path/to/apisix-python-plugin-runner/apisix/plugin

the .py files in this directory autoload

Plugin example

/path/to/apisix-python-plugin-runner/apisix/plugin/say.py

Plugin Format

from apisix.runner.plugin.base import Base
from apisix.runner.http.request import Request
from apisix.runner.http.response import Response


class Say(Base):
    def __init__(self):
        super(Say, self).__init__(self.__class__.__name__)

    def filter(self, request: Request, response: Response):
        headers = request.headers
        headers["X-Resp-A6-Runner"] = "Python"
        response.body = "Hello, Python Runner of APISIX"
        response.headers = headers
  • The plugin must inherit the Base class
  • The plugin must implement the filter function
  • filter function parameters can only contain Request and Response classes as parameters
  • Request parameter can get request information
  • Response parameter can set response information
  • self.config can get plug-in configuration information

Test

Run make test.

Data Format

FlatBuffers

Data Protocol

1 byte of type + 3 bytes of length + data