Skip to main content

CactusKIT SDK package

Project description

CactusKIT

Lightweight Python SDK for declaring small API handlers and producing consistent responses.

See package metadata in pyproject.toml.

Quick links

Overview

CactusKIT provides a single-purpose decorator cactuize to declare API entrypoints and a small response wrapper CactusResponse so handlers return consistent, serializable objects.

Key pieces:

  • cactuize(...) : decorator that validates/binds args, optionally enforces auth, and normalizes return values into CactusResponse.
  • CactusResponse / make_res() : response object and factory with helpers (size, hash, timestamp).
  • CactusEncoder : JSON encoder that can serialize CactusResponse instances.
  • Enums: HttpStatus, ApiProtocol, ApiMethod.

Installation

Install from source or PyPI when available:

pip install cactuskit

Usage

Import the symbols from the module and declare handlers with cactuize.

from cactuskit import ApiMethod, ApiProtocol, HttpStatus, cactuize

def authenticate():
    return True

@cactuize()
def simple_entrypoint():
    return f"Hello World from {simple_entrypoint}"

@cactuize(
    auth=authenticate,
    protocol=ApiProtocol.HTTP,
    method=ApiMethod.GET)
def entrypoint(name):
    return (HttpStatus.HTTP_CUSTOM(201), {
        "content": f"Hello {name}"
    })

Notes:

  • Handler functions may return a plain payload (dict or str) or a tuple (HttpStatus, payload).
  • If auth is provided to cactuize, it should be a callable returning truthy when authorized.

API Reference (short)

  • cactuize(protocol=ApiProtocol, method=ApiMethod, auth=None, middleware=None, args_mtable=None) : declare a function as a Cactus entrypoint. Performs argument binding and converts results into CactusResponse objects. When auth is provided, it is called and a failed check returns a plain "Authentication required" string.
  • CactusResponse(payload, status_code) : wrapper with helpers: get_payload(), get_status_code(), get_timestamp(), get_payload_size(), get_payload_hash().
  • make_res(payload, status_code=HttpStatus.HTTP_OK) : helper factory.
  • CactusEncoder : json.JSONEncoder subclass that serializes CactusResponse instances.

Development

  • Create a virtualenv and install dev dependencies (if any).
python -m venv .venv
source .venv/bin/activate
pip install -e .

Contributing

Contributions welcome. Open issues or pull requests and include tests for new behavior.

License

MIT : see LICENSE.

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

cactuskit-0.2.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

cactuskit-0.2.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file cactuskit-0.2.0.tar.gz.

File metadata

  • Download URL: cactuskit-0.2.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for cactuskit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0f49346e685868f0f14a2c4ef5ee9afd8fd9295bbe479c66cbf453cfc83c317b
MD5 8f844381044596b985a2fba6aef03d49
BLAKE2b-256 86b7e1b874760457e6c3153cd233704a18a22fe78083ee1e1af56c0b6207be52

See more details on using hashes here.

File details

Details for the file cactuskit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cactuskit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for cactuskit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d6ad5ace72d85658f6becf05c3326a41078c70da2fc706ec12f6dc0d37f9720
MD5 5ccedbd638a0f2836ad0bd2cc3647ff6
BLAKE2b-256 0c3f6a40b811557b591fcb1ff13c4a9324531dd5c00a4a59a1bec65a6c54b996

See more details on using hashes here.

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