Skip to main content

A pure Python framework for building HAProxy SPOE agents

Project description

SPOE Forge

A pure Python framework for building SPOE (Stream Processing Offload Engine) agents that communicate with HAProxy using the SPOA protocol.

License: MIT Python 3.12+ Coverage Status

Overview

SPOE Forge provides a clean, decorator-based API for creating agents that process HAProxy messages and return actions. Built with async/await throughout, it's designed for high-performance production environments. Or at least as performant as python will allow.

Why SPOE Forge?

Originally created to power a Google OAuth2 authentication backend for HAProxy, it became clear the project could be converted to an abstracted framework. I noticed during the development of this project that there was a lack of well-maintained, easily understood implementations of the SPOA protocol in python.

Key Features

  • Simple decorator-based API - Register message handlers with @agent.message()
  • Full SPOP protocol support - Complete implementation of the SPOA protocol
  • Health check support - Built-in HAProxy health check handling

Installation

Install from PyPI:

pip install spoe-forge

Quick Start

Basic Example

from spoe_forge import (
    SpoeForge,
    AgentContext,
    SetVarAction,
    ActionScope
)

# Create an agent
agent = SpoeForge(name="my-agent", debug=False)

# Register a message handler
@agent.message("check-request")
def handle_request(ctx: AgentContext) -> list[SetVarAction]:
    """Process incoming request and set HAProxy variables"""

    # Get message arguments from HAProxy
    client_ip = ctx.get_arg("client_ip")
    request_path = ctx.get_arg("path")

    # Your business logic here
    is_allowed = check_access(client_ip, request_path)

    # Return actions to set HAProxy variables
    return [
        SetVarAction(
            scope=ActionScope.TRANSACTION,
            name="access_allowed",
            value=is_allowed
        )
    ]

# Start the server
if __name__ == "__main__":
    agent.run(host="0.0.0.0", port=12345)

HAProxy Configuration

SPOE Forge works with HAProxy's SPOE configuration. For details on configuring HAProxy to communicate with your agent, see the official HAProxy SPOE documentation.

Local Development

Running with Docker

A complete local development environment is provided using Docker Compose, including a sample SPOE agent, HAProxy, and a test backend service.

Quick start:

cd docker
docker compose up --build

This starts three services:

  • SPOA Agent (spoa) - Sample SPOE Forge agent running on port 8500
  • Whoami (whoami) - Simple backend service for testing
  • HAProxy (haproxy) - Configured to communicate with the WhoAmI example BE Service, the SPOA agent, and is listening on port 8080

Test the setup:

# Open logs
docker compose logs

# Visit the dev url in your browser
http://localhost:8080

Check both the docker logs and the X-Test-Arg header displayed on the WhoAmI page.

Make any updates to the HAProxy configs or the sample_server.py files in ./docker/ to support your testing.

Roadmap

Future enhancements under consideration with no timeline guaranteed:

  • Middleware support
  • Much more extended documentation and examples

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Any and all contributions welcome.

Support

For issues and questions, please file an issue on GitHub.

Acknowledgments

Built to solve real-world production needs for HAProxy SPOA agents. Special thanks to the HAProxy team for excellent documentation of the SPOE protocol.

Extra shoutout to Christopher Faulet for responding to some questions about a few hiccups along the way.

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

spoe_forge-0.0.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

spoe_forge-0.0.1-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

Details for the file spoe_forge-0.0.1.tar.gz.

File metadata

  • Download URL: spoe_forge-0.0.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spoe_forge-0.0.1.tar.gz
Algorithm Hash digest
SHA256 74facc5711e81ba96227f80fe6cb6d6c9215957c338e82b112bdd67a8ae5fecb
MD5 1c0fc5557053252efba60a79472d0310
BLAKE2b-256 38db9a12c376610f43b1f66b68ece3652f81208ece0782353752c3ebdc128385

See more details on using hashes here.

Provenance

The following attestation bundles were made for spoe_forge-0.0.1.tar.gz:

Publisher: release.yml on mwodonnell/spoe-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spoe_forge-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: spoe_forge-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 28.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spoe_forge-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b8e446a99d9cbbf7159ec95a029c32ad38ea96b765d6f4caefb07db80e763ca
MD5 ee8d2f267e3fd334af8c7b8a046cc4b1
BLAKE2b-256 f67d4afa3213e9edfc3393fee99b7172cb4deb1ad6fc1d56b7feed1cc286d0af

See more details on using hashes here.

Provenance

The following attestation bundles were made for spoe_forge-0.0.1-py3-none-any.whl:

Publisher: release.yml on mwodonnell/spoe-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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