explaingit

hugapi/hug

6,893PythonAudience · developerComplexity · 2/5Setup · easy

TLDR

A Python framework that turns plain functions into web API endpoints using simple decorators, with automatic type checking, input validation, documentation generation, and versioning built in.

Mindmap

mindmap
  root((hug))
    What it does
      REST API from functions
      Auto type validation
      Auto documentation
    Key Features
      Decorator-based routing
      API versioning
      hug.test module
    Tech Stack
      Python
      Falcon
      WSGI servers
    Use Cases
      Rapid API prototyping
      Versioned endpoints
      No-boilerplate APIs
    Audience
      Python developers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Turn a Python function into a REST API endpoint in a few lines without writing routing or validation boilerplate.

USE CASE 2

Build a versioned API where older clients keep working while newer clients receive updated routes.

USE CASE 3

Test API endpoints without running a server by calling the original Python functions directly in unit tests.

Tech stack

PythonFalcon

Getting it running

Difficulty · easy Time to first run · 5min

Project is in maintenance mode and mostly stable but not actively developed since around 2020.

In plain English

Hug is a Python framework for building APIs, which are the interfaces that let one piece of software talk to another. The idea behind hug is that writing an API endpoint should feel as close as possible to writing a regular Python function. You decorate a function with a simple annotation like @hug.get, and hug automatically exposes it as a web endpoint, handles incoming requests, validates inputs, and generates documentation for the API. The whole setup to get a working web endpoint takes just a few lines of code. Hug works with HTTP methods like GET, POST, and PUT, and it handles routing, input type checking, and output formatting. When you annotate a function argument with a type like int or a custom type, hug uses that to validate and convert incoming data before it reaches your function. This means less repetitive validation code scattered throughout your logic. The same type annotations also feed into automatic documentation that hug generates and serves at a /documentation path on your running server. One notable feature is built-in API versioning. You can mark different versions of the same endpoint separately, and callers can request a specific version either through the URL path or an HTTP header. This makes it straightforward to keep older clients working while releasing changes for newer ones. Testing is designed to stay simple. Because hug does not modify the original Python functions you decorate, you can call them directly in tests without spinning up a server. Hug also provides a hug.test module that simulates HTTP calls against your API so you can test the full stack in a controlled way. Hug is built on top of Falcon, a fast HTTP library for Python. It requires Python 3 and can run on any standard server that supports the WSGI interface, including uWSGI and Gunicorn. It installs via pip. The project appears to be in maintenance mode with most of its activity predating 2020, but the library is stable and the README reflects a mature, documented feature set.

Copy-paste prompts

Prompt 1
Using hug, show me how to expose a Python function as a GET endpoint at /greet that accepts a name parameter and returns a JSON greeting.
Prompt 2
I am building a versioned API with hugapi/hug. Show me how to define version 1 and version 2 of the same endpoint so old clients still get the v1 response.
Prompt 3
Using hug, write an endpoint that accepts a POST request with an integer and a string, validates the types automatically, and returns an error if the types are wrong.
Prompt 4
How do I test a hug API endpoint without spinning up a server? Show me how to use hug.test to simulate a GET request and check the response.
Open on GitHub → Explain another repo

← hugapi on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.