Skip to main content

Beta version of JEC API

Project description

JEC-API

Features

  • Class-Based Routes: Group related endpoints (e.g., CRUD operations) into a single class.
  • Auto-Discovery: Automatically find and register route classes from your project packages.
  • Smart Method Naming: API paths and HTTP methods are inferred from your method names (e.g., get_by_id becomes GET /{id}).
  • FastAPI Native: Fully compatible with FastAPI dependencies, models, and OpenAPI generation.

Installation

pip install jec-api

Quick Start

  1. Define a Route Class
# routes.py
from jec_api import Route

class Users(Route):
    # Optional: explicitly set path, otherwise defaults to /users
    # path = "/my-users"

    async def get(self):
        """List all users"""
        return [{"id": 1, "name": "Alice"}]

    async def get_by_id(self, id: int):
        """Get user by ID"""
        return {"id": id, "name": "Alice"}

    async def post(self, name: str):
        """Create a user"""
        return {"id": 2, "name": name}
  1. Create the App
# main.py
from jec_api import Core

core = Core(title="My API")

# Auto-discover routes from a module/package
core.discover("routes")

# Or register manually
from routes import Users
core.register(Users)
  1. Run it
uvicorn main:core --reload

Usage Guide

Defining Routes

Inherit from jec_api.Route to create a route group. The class name is automatically converted to kebab-case to form the base path (e.g., UserProfiles -> /user-profiles), unless you override it with the path attribute.

Method Naming Convention

JEC-API parses your method names to determine the HTTP verb and path parameters:

Method Name HTTP Verb Generated Path
get() GET /
post() POST /
get_by_id(id) GET /{id}
delete_by_id(id) DELETE /{id}
get_users() GET /users
post_batch_update() POST /batch-update

Path Parameters

To define path parameters, use the _by_{param} pattern in your method name. For example, get_by_user_id will generate a path /{user_id}.

Manual Registration

You can register routes manually if you prefer not to use auto-discovery:

from my_routes import MyRoute
app.register(MyRoute, tags=["Custom Tag"])

Auto-Discovery

The discover() method recursively searches the specified package for any classes inheriting from Route and registers them.

app.discover("src.routes")

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.1.tar.gz (6.7 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.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file jec_api-0.0.1.tar.gz.

File metadata

  • Download URL: jec_api-0.0.1.tar.gz
  • Upload date:
  • Size: 6.7 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.1.tar.gz
Algorithm Hash digest
SHA256 42d8fffabf355ab6d1e42494cad737bd7c63f23be7c3e9ea48d0680bbf1c106c
MD5 84276c460845b542cfd96715cb48bfc5
BLAKE2b-256 ffe60f7af1ba756ad0bca52fda354f17d1f42843860dbf8497a71a462fcf07ff

See more details on using hashes here.

File details

Details for the file jec_api-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: jec_api-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f503796cc50793766bec271ba183875c123d6f4964c5dbaf1a665b3b2a479d6b
MD5 1528273b65fdec7a1b48ab56b3950ff1
BLAKE2b-256 ed78f3c9ed8b3e96363b59d9c38012ba352c004bb34fec92e1e2c846e8396d7d

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