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_idbecomesGET /{id}). - FastAPI Native: Fully compatible with FastAPI dependencies, models, and OpenAPI generation.
Installation
pip install jec-api
Quick Start
- 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}
- 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)
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42d8fffabf355ab6d1e42494cad737bd7c63f23be7c3e9ea48d0680bbf1c106c
|
|
| MD5 |
84276c460845b542cfd96715cb48bfc5
|
|
| BLAKE2b-256 |
ffe60f7af1ba756ad0bca52fda354f17d1f42843860dbf8497a71a462fcf07ff
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f503796cc50793766bec271ba183875c123d6f4964c5dbaf1a665b3b2a479d6b
|
|
| MD5 |
1528273b65fdec7a1b48ab56b3950ff1
|
|
| BLAKE2b-256 |
ed78f3c9ed8b3e96363b59d9c38012ba352c004bb34fec92e1e2c846e8396d7d
|