Skip to main content

haproxy-cli

CI PyPI version

haproxy-cli - A tool to interact with HAProxy.

Table of Contents

  1. Overview
  2. Install
  3. Modes
  4. CLI Usage
  5. Examples
  6. Development

Overview

haproxy-cli is a tool to manage the various aspects of HAProxy that can be controlled by means of its socket. It is based on haproxyctl and is actively used in the OPNsense HAProxy plugin.

Install

pip install haproxy-cli

Modes

haproxy-cli can be used in 2 modes: CLI mode and Python API mode. CLI mode, as the name implies, gives you a command, haproxy-cli, that can be used to control HAProxy.

You can use the Python API mode to integrate haproxy-cli directly in your Python project.

Every command in haproxy-cli has at least two methods: getResult and getResultObj.

The method getResult returns a formatted string with the results obtained by executing the given HAProxy command, while getResultObj returns a Python object with the results, making it easy to use this results in some Python code.

CLI Usage

$ haproxy-cli --help

usage: haproxy-cli [-h] [-v] [-c COMMAND] [-l] [-H] [-s SERVER] [-b BACKEND]
                  [-w WEIGHT] [-k SOCKET]

A tool to interact with HAProxy

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Be verbose.
  -c COMMAND, --command COMMAND
                        Type of command. Default info
  -l, --list-commands   Lists available commands.
  -H, --help-command    Shows help for the given command.
  -s SERVER, --server SERVER
                        Attempt action on given server.
  -b BACKEND, --backend BACKEND
                        Set backend to act upon.
  -w WEIGHT, --weight WEIGHT
                        Specify weight for a server.
  -k SOCKET, --socket SOCKET
                        Socket to talk to HAProxy. It accepts
                        unix:///path/to/socket or tcp://1.2.3.4[:port]
                        addresses. If there is no match
                        for protocol, then it assumes a UNIX socket file.

Examples

CLI

$ haproxy-cli -c frontends

$ haproxy-cli -c servers -b example_backend

$ haproxy-cli -c get-weight -b example_backend -s server1

$ haproxy-cli -c set-weight -b example_backend -s server1 -w 99

$ haproxy-cli -k /run/haproxy/admin.sock -c backends

API

#!/usr/bin/env python

from haproxy.conn import HaPConn
from haproxy import cmds

try:
    socket_conn = HaPConn('/var/run/haproxy.socket')

    if socket_conn:
        print(socket_conn.sendCmd(cmds.showInfo()))
    else:
        print('Could not open socket')

except Exception as exc:
    print(exc)

Development

Contributing

Please use the GitHub issues functionality to report any bugs or requests for new features. Feel free to fork and submit pull requests for potential contributions.

Metadata

Release files for haproxy-cli 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for haproxy-cli 0.7.2
File Size Uploaded Provenance Actions
haproxy_cli-0.7.2.tar.gz 31.2 kB Without provenance Details for haproxy_cli-0.7.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for haproxy-cli 0.7.2
File Interpreter ABI Platform Actions
haproxy_cli-0.7.2-py3-none-any.whl Python 3 none any Details for haproxy_cli-0.7.2-py3-none-any.whl

Total release size: 61.5 kB

Release files / haproxy_cli-0.7.2.tar.gz

Download URL haproxy_cli-0.7.2.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c5610bbc46e457a091e26122b1dd62bacad22dc3f70ce6043e5a4fe4abebdd04
BLAKE2b-256 checksum
How to use checksums
9f9bc64f34d3b42dbb0ca284e0501a1197231c14f9c91be99d5e27b407c2ff92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / haproxy_cli-0.7.2-py3-none-any.whl

Download URL haproxy_cli-0.7.2-py3-none-any.whl
Size 30.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f8db02f7804f3dee467fe4eef34cf4fde8a34e2a41d17aad747efe478ce694a
BLAKE2b-256 checksum
How to use checksums
aaca172dc81914975b3fa6698846bd42a6b2df3d41b401c0931376ead913ac13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for haproxy-cli 0.7.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page