Skip to main content

easy-api-builder

A lightweight Flask wrapper for building JSON APIs without boilerplate. Register endpoints, authentication, and error handling in a single fluent call, then consume any API with the built-in easy_request helper.


Installation

pip install easy-api-builder

Quick start

from api_builder import ApiBuilder, easy_request

api = ApiBuilder()

api.get("/status", {"ok": True})
api.run()

Visit http://localhost:5000/status — done.


ApiBuilder

Constructor

api = ApiBuilder(
    name=__name__,         # Flask app name
    template_folder="templates",  # folder for HTML error pages
    debug=False,           # enable Flask debug mode
)

Registering endpoints

All registration methods return self, so calls can be chained.

.get(path, payload, *, auth_keys, handler)

# Static payload
api.get("/hello", {"message": "Hello, world!"})

# Key-protected
api.get("/secret", {"data": 42}, auth_keys=["abc123", "xyz789"])

# Custom handler
def my_handler():
    from flask import jsonify, request
    return jsonify({"echo": request.args.get("q")})

api.get("/echo", handler=my_handler)

.post(path, payload, *, auth_keys, handler)

Same signature as .get(), registers a POST endpoint.

from flask import jsonify, request

def handle_submit():
    body = request.get_json()
    return jsonify({"received": body})

api.post("/submit", handler=handle_submit)

.route(path, methods, payload, *, auth_keys, handler)

Register any HTTP verb or combination of verbs.

api.route("/ping", ["GET", "POST"], {"pong": True})

Starting the server

# Blocking — use for production-style scripts
api.run(host="0.0.0.0", port=5000)

# Non-blocking daemon thread — use when running alongside other code
thread = api.run_async(port=5000)

Authentication

Pass auth_keys to any registration method. Requests must include ?key=<value> in the URL.

api.get("/private", {"data": "secret"}, auth_keys=["abc123"])
Scenario Status Response
No key supplied 401 {"error": "API key required."}
Wrong key 403 {"error": "Invalid API key."}
Valid key 200 Your payload

Error handling

All HTTP errors are returned as JSON automatically — no setup required.

{
  "code": 404,
  "name": "Not Found",
  "description": "..."
}

If a templates/404.html file exists it will be rendered for 404s; otherwise the JSON fallback is used.


easy_request

A thin wrapper around requests with built-in error handling.

easy_request(
    url,               # target URL (required)
    method="GET",      # HTTP verb
    params=None,       # URL query parameters (dict)
    json_body=None,    # request body sent as JSON (dict)
    headers=None,      # extra headers (dict)
    timeout=10,        # socket timeout in seconds
    api_key=None,      # appended as ?key= automatically
)

Returns a parsed JSON dict on success, or a safe error dict on failure.

# Simple GET
data = easy_request("https://api.example.com/users")

# Authenticated
data = easy_request("http://localhost:5000/secret", api_key="abc123")

# POST with body
data = easy_request(
    "http://localhost:5000/submit",
    method="POST",
    json_body={"name": "Alice"},
)

Error responses

{"error": "Request timed out.",  "url": "..."}          # timeout
{"error": "...",  "status_code": 403}                   # HTTP error
{"error": "Non-JSON response.",  "body": "..."}          # non-JSON body

Full example

from flask import jsonify, request
from api_builder import ApiBuilder, easy_request

api = ApiBuilder()

# Public status endpoint
api.get("/status", {"ok": True})

# Protected data endpoint
api.get("/data", {"value": 99}, auth_keys=["secret-key"])

# Dynamic POST handler
def echo():
    return jsonify(request.get_json())

api.post("/echo", handler=echo)

# Start in background thread
api.run_async(port=5000)

# Consume the protected endpoint
result = easy_request("http://localhost:5000/data", api_key="secret-key")
print(result)  # {"value": 99}

License

MIT

Metadata

Release files for easy-api-builder 2026.1.1

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

Source distribution (sdist)

Source distribution for easy-api-builder 2026.1.1
File Size Uploaded
easy_api_builder-2026.1.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easy-api-builder 2026.1.1
File Interpreter ABI Platform
easy_api_builder-2026.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / easy_api_builder-2026.1.1.tar.gz

Download URL easy_api_builder-2026.1.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6767915f9dc259fcca017b188ff5f5fe4db2287c47e6229926ee9275ce7bc54c
BLAKE2b-256 checksum
How to use checksums
78e969cd430efd3b5bf130269836fb5cdc1cfac6b590305ce9fb2200be74d195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / easy_api_builder-2026.1.1-py3-none-any.whl

Download URL easy_api_builder-2026.1.1-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86e8e3b7ff64647a71d981f69d9c6715a34f30c61ab7e0677d226eeb82ee9e5f
BLAKE2b-256 checksum
How to use checksums
6617a8900ced05d1e98695959230c680c4eabcc41824fce029d14c33d738b764
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

2026.1.1 This release

2 release files

0.3.1

1 release file

0.3

1 release file

0.2

1 release file

0.1.1

1 release file

0.1

1 release file

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