Skip to main content

Just Encapsulated Controllers — The Class-Based System for Application Program Interfaces

Project description

JEC-API

A powerful wrapper around FastAPI that brings class-based routing, strict method mapping, and modern developer tools to your API development.

Features

  • Class-Based Routes: Group related endpoints into a single class for better organization.
  • Strict Method Mapping: Methods named get, post, put, etc., are automatically mapped to HTTP verbs.
  • Data Object Support: Native Pydantic integration for automatic request/response validation and schema generation.
  • API Decorators: Built-in @log, @speed, and @version decorators for observability and control.
  • Programmatic Configuration: Unified core.tinker() method to configure FastAPI and Uvicorn.
  • JEC DevTools: Real-time, dark-themed developer console at /__dev__ for monitoring traffic and performance.

Installation

pip install jec-api

Quick Start

  1. Define a Route Class
from pydantic import BaseModel
from jec_api import Route, log, speed

class UserResponse(BaseModel):
    id: int
    name: str

class Users(Route):
    @log
    @speed
    async def get(self) -> list[UserResponse]:
        """List all users with logging and speed tracking"""
        return [UserResponse(id=1, name="Alice")]
  1. Configure and Run
from jec_api import Core
from routes import Users

core = Core()
core.tinker(
    title="My API",
    dev=True,      # Enable JEC DevTools
    reload=True    # Auto-reload on changes
)

core.register(Users)

if __name__ == "__main__":
    core.run(port=8000)

Usage Guide

Defining Routes

Inherit from jec_api.Route. The class name is converted to kebab-case for the base path (e.g., UserProfiles -> /user-profiles), unless overridden with the path attribute.

Method Mapping

Methods named exactly after HTTP verbs (e.g., get, post) are registered as endpoints. Others are ignored.

API Decorators

Enhance your endpoints with built-in decorators:

  • @log: Logs function calls, arguments, and return values/exceptions.
  • @speed: Measures execution time in milliseconds.
  • @version(">=1.0.0"): Enforces semver constraints via the X-API-Version header.

Configuration (core.tinker())

The tinker() method provides a unified interface for configuration:

  • FastAPI Options: title, description, version, docs_url, etc.
  • Uvicorn Options: host, port, reload, log_level, etc.
  • DevTools: Set dev=True to enable the developer console.
  • Versioning: strict_versioning=True to require version headers on all versioned routes.

JEC DevTools

Access a premium, real-time monitoring dashboard at /__dev__ (or your custom dev_path). It provides:

  • Live request/response tracking via SSE.
  • Visual execution timing (Green/Yellow/Red).
  • Expanded logs for @log decorated methods.
  • Version check results.

License

MIT 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

jec_api-0.0.8a0.tar.gz (127.6 kB view details)

Uploaded Source

Built Distribution

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

jec_api-0.0.8a0-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file jec_api-0.0.8a0.tar.gz.

File metadata

  • Download URL: jec_api-0.0.8a0.tar.gz
  • Upload date:
  • Size: 127.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for jec_api-0.0.8a0.tar.gz
Algorithm Hash digest
SHA256 06977b3aa2481349eb0f3c7adbcac3b891f3752f6bc9ffd6d191dbc400f963c0
MD5 cf6ae647ad69433583056fa48b0492e5
BLAKE2b-256 45c6f817326a65107c37251ace5754a0517ee69d4a50c3f5c129acfdec81f6b6

See more details on using hashes here.

File details

Details for the file jec_api-0.0.8a0-py3-none-any.whl.

File metadata

  • Download URL: jec_api-0.0.8a0-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for jec_api-0.0.8a0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca00527d37dc16267a1e86bd3e03ccb99c5501052dca4160b12b809aac690da5
MD5 ec84d7786647ffb23a19ffb10f707c1a
BLAKE2b-256 96c26f31945e86aa3d6d926fb23091d6ddb9192fa17a2c78c7ae11ef5393245c

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