### Example GET Request with Parameters Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md An example of an HTTP GET request including label and value parameters for badge generation. ```http GET /?label=Coverage&value=95% HTTP/1.1 Host: localhost:8000 ``` -------------------------------- ### CLI Usage Examples Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md Demonstrates various ways to start the anybadge server from the command line, including specifying address and port, enabling debug mode, and utilizing environment variables for configuration. ```bash # Start server on default localhost:8000 anybadge-server # Start on custom port anybadge-server -p 9000 # Start on all interfaces on port 5000 anybadge-server -l 0.0.0.0 -p 5000 # Enable debug logging anybadge-server -d # Use environment variables export ANYBADGE_PORT=9000 export ANYBADGE_LISTEN_ADDRESS=0.0.0.0 anybadge-server ``` -------------------------------- ### Start anybadge Server Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md Start the anybadge server from the terminal. Use the -p flag to specify the port and -d for debug logging. This example shows starting on port 8000. ```bash # Terminal 1: Start server on port 8000 anybadge-server -p 8000 -d # With debug logging # Terminal 2: Request a badge curl "http://localhost:8000/?label=Build&value=passing" # Returns: SVG badge with label "Build" and value "passing" ``` -------------------------------- ### Start Anybadge Server with Default Settings Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/endpoints.md Starts the Anybadge server on the default host (localhost) and port (8000). ```bash anybadge-server ``` -------------------------------- ### Start Anybadge Server Listening on All Interfaces Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/endpoints.md Starts the Anybadge server and configures it to listen on all available network interfaces on a specified port. ```bash anybadge-server --listen-address 0.0.0.0 --port 5000 ``` -------------------------------- ### Start Anybadge Server with Debug Logging Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/endpoints.md Starts the Anybadge server with debug logging enabled for more detailed output. ```bash anybadge-server --debug ``` -------------------------------- ### Example GET Request Missing Parameters Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md An example of an HTTP GET request where label and value parameters are missing, triggering the help page response. ```http GET / HTTP/1.1 Host: localhost:8000 ``` -------------------------------- ### Start Anybadge Server on a Custom Port Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/endpoints.md Starts the Anybadge server on a specified custom port. ```bash anybadge-server --port 9000 ``` -------------------------------- ### Install build requirements Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Install the necessary packages for building the project using pip. ```bash pip install -r build-requirements.txt ``` -------------------------------- ### Install and activate pre-commit hooks Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Install pre-commit and activate it for the project to ensure code consistency and run safety checks before committing. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### run() Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md Starts and runs the anybadge HTTP server. It can be configured with a specific listen address and port. ```APIDOC ## run() ### Description Starts and runs the anybadge HTTP server. It can be configured with a specific listen address and port. ### Method ```python def run( listen_address: str | None = None, port: int | None = None ) -> None ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from anybadge.server.cli import run # Start server on default localhost:8000 run() # Start on custom address run(listen_address='0.0.0.0', port=9000) ``` ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Start HTTP Server Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/README.md Launch the Anybadge HTTP server to serve badges dynamically. The server defaults to port 8000. ```bash # Start server on default port 8000 anybadge-server ``` -------------------------------- ### Build, install, and run CLI tests locally Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Build the package, install it locally, and then run CLI tests. This is particularly useful when actively developing CLI code, as it ensures changes are reflected in tests. ```bash inv package.build && inv package.install && inv test.cli ``` -------------------------------- ### Example HTML Help Page Response Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md The HTML response served when required parameters are missing from a GET request. ```html HTTP/1.1 200 OK Content-type: text/html Anybadge Web Server.

Welcome to the Anybadge Web Server.

You are seeing this message because...

... ``` -------------------------------- ### Pre-commit hook example output Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Example output from pre-commit hooks indicating that files were modified and need to be re-added and re-committed. ```text trim trailing whitespace.................................................Failed - hook id: trailing-whitespace - exit code: 1 - files were modified by this hook Fixing tests/test_anybadge.py fix end of files.........................................................Failed - hook id: end-of-file-fixer - exit code: 1 - files were modified by this hook Fixing examples/color_teal.svg ``` -------------------------------- ### Example HEAD Request Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md An example of an HTTP HEAD request to the server. ```http HEAD / HTTP/1.1 Host: localhost:8000 ``` -------------------------------- ### Help Response for Missing Parameters Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/endpoints.md This example shows the response when required parameters (label and value) are missing. It returns an HTML help page with usage instructions and an example link. ```http GET / HTTP/1.1 Host: localhost:8000 ``` ```html HTTP/1.1 200 OK Content-type: text/html Anybadge Web Server.

Welcome to the Anybadge Web Server.

You are seeing this message because you haven't passed all the query parameters to display a badge.

You need to pass at least a label and value parameter.

Here is an example:

http://localhost:8000/?label=Project%20Awesomeness&value=110%

``` -------------------------------- ### Generate example badges markdown Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Run this task to regenerate the example badges markdown. This should be done whenever badge appearance or available colors are modified. ```bash inv examples ``` -------------------------------- ### FONT_WIDTHS Configuration Example Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/configuration.md Illustrates the structure for defining character widths for different fonts and sizes, crucial for accurate badge rendering. ```python FONT_WIDTHS = { "DejaVu Sans,Verdana,Geneva,sans-serif": { 10: 9, # 10px font = 9px average character width 11: 10, # 11px font = 10px average character width 12: 11, # 12px font = 11px average character width }, "Arial, Helvetica, sans-serif": { 11: 8, # 11px font = 8px average character width }, } ``` -------------------------------- ### Run local tests Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Execute local tests by first building and installing the package, then running the local test suite. This ensures the project builds and installs correctly. ```bash inv package.build && inv package.install && inv test.local ``` -------------------------------- ### GitHub Readme Badge Example Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/README.md Example Markdown for displaying badges in a GitHub README file. This shows how to link badges to relevant project pages or build statuses. ```markdown # My Project [![Build Status](https://github.com/user/repo/workflows/CI/badge.svg)](https://github.com/user/repo/actions) [![Coverage](https://img.shields.io/badge/coverage-95%25-brightgreen)](https://github.com/user/repo) Generated with anybadge. ``` -------------------------------- ### Install and run Tox tests Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Install the Tox testing tool and run tests against all supported Python versions. This ensures compatibility across different Python environments. ```bash pip install tox tox ``` -------------------------------- ### CLI Style Matching Example Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/style.md Demonstrates how the Anybadge CLI parses a style name provided as an argument. It matches the style, extracts its properties, and creates a badge. ```bash # Command: anybadge --value=2.22 --file=pylint.svg pylint # Parsing: # 1. Detect 'pylint' matches Style.PYLINT # 2. Extract: thresholds={2: 'red', 4: 'orange', 8: 'yellow', 10: 'green'}, label='pylint' # 3. Create: Badge('pylint', 2.22, thresholds={...}) ``` -------------------------------- ### Install Anybadge Package Source: https://github.com/jongracecox/anybadge/blob/master/README.md Install the latest release of the anybadge package from PyPi using pip. This command also makes the 'anybadge' utility available on the command line. ```bash pip install anybadge ``` -------------------------------- ### Clone the anybadge repository Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Use this command to get a local copy of the project. ```bash git clone https://github.com/jongracecox/anybadge.git ``` -------------------------------- ### Configure Anybadge Server via Environment Variables Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/endpoints.md Sets environment variables to configure the Anybadge server's port, listen address, and log level before starting it. ```bash export ANYBADGE_PORT=9000 export ANYBADGE_LISTEN_ADDRESS=0.0.0.0 export ANYBADGE_LOG_LEVEL=DEBUG anybadge-server ``` -------------------------------- ### Run CLI tests against local install Source: https://github.com/jongracecox/anybadge/blob/master/CONTRIBUTING.md Execute command-line interface tests against a locally installed version of the package. Useful for verifying CLI functionality during development. ```bash inv test.cli ``` -------------------------------- ### Main Server Entry Point Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md The main function to run the anybadge server, incorporating support for CLI arguments and environment variables. It handles configuration, logging setup, and initiates the server run process. ```python from anybadge.server.cli import main # When called as command-line entry point main() ``` -------------------------------- ### Access Server from Application Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/api-reference/server.md Make a GET request to the running anybadge server to generate an SVG badge. The response content, which is the SVG, can then be saved to a file. ```python import requests # Request a badge from the server response = requests.get('http://localhost:8000/', params={ 'label': 'Coverage', 'value': '95%' }) # Write SVG to file with open('coverage.svg', 'wb') as f: f.write(response.content) ``` -------------------------------- ### Badge Generation URL Example Source: https://github.com/jongracecox/anybadge/blob/master/_autodocs/endpoints.md Illustrates how to construct a URL to generate a badge with a specific label and value. Ensure query parameters are URL-encoded. ```http GET /?label=