Skip to main content

No project description provided

Project description

FastAPI Opinionated Core

FastAPI Opinionated Core is the foundational engine of an opinionated framework built on top of FastAPI.
It provides structured routing, decorator-based controllers, automatic controller discovery, and enhanced logging.

⚠️ Important:
This package contains only the core framework logic.
If you want a ready-to-use application template (with complete folder structure, examples, and boilerplate),
use the official starter project:

👉 https://github.com/Azzarnuji/fastapi-opinionated-starter

The starter repository is built on top of this core package.


Features

  • Decorator-based routing (@Controller, @Get, @Post, etc.)
  • Automatic controller discovery from domain folders
  • Enhanced logging (colors, timestamps, PID, file references, delta timing)
  • Opinionated project structure for consistent FastAPI development
  • Fully compatible with FastAPI and Uvicorn

Installation

pip install fastapi-opinionated-core

Quick Start (Using the Core Directly)

1. Define a controller

# app/domains/user/controller.py
from fastapi_opinionated.decorators.routing import Controller, Get, Post

@Controller("/users")
class UserController:

    @Get("/")
    def list_users(self):
        return ["john", "jane", "bob"]

    @Post("/create")
    def create_user(self):
        return {"message": "User created successfully"}

2. Create your application

# main.py
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi_opinionated.app import App


@asynccontextmanager
async def lifespan(app: FastAPI):
    try:
        # Startup code here
        yield
        # Shutdown code here
    except Exception as e:
        print(f"Lifespan error: {e}")

app = App.create(lifespan=lifespan)

3. Run your application

fastapi dev main.py --host 0.0.0.0 --port 8003

Recommended: Use the Starter Template

To get a complete project structure,
use the official starter template:

👉 https://github.com/Azzarnuji/fastapi-opinionated-starter

It includes:

  • A full domain-based folder layout
  • Configured development environment
  • Predefined controllers and examples
  • Ready-to-run application structure

Decorators

The routing system provides the following decorators:

  • @Controller(base_path) – Marks a class as a controller
  • @Get(path) – Defines a GET route
  • @Post(path) – Defines a POST route
  • @Http(method, path) – Defines custom HTTP methods

All decorated methods are discovered and registered automatically.


Architecture Overview

App (Core Engine)

App.create() handles:

  • Initializing the FastAPI application
  • Applying the custom logging configuration
  • Discovering controller modules
  • Registering routes via FastAPI

App.listen() [Not Completed] handles:

  • Starting the Uvicorn server
  • Passing through all Uvicorn configuration parameters

Routing System

  • Searches for controllers inside domain folders
  • Automatically discovers routes based on decorators
  • Registers endpoints using FastAPI’s APIRouter

Example generated route:

[GET] /users/ -> UserController.list_users

Logging System

The custom logger includes:

  • Color-coded log levels
  • Process ID (PID)
  • Timestamps
  • Delta time measurement
  • File and line number tracking

Ideal for debugging and profiling.


Configuration

App.create()

Accepts all FastAPI constructor arguments:

App.create(
    title="My API",
    docs_url="/docs",
    lifespan=my_lifespan
)

App.listen() [Not Completed]

Accepts all Uvicorn parameters:

App.listen(app, reload=True, host="0.0.0.0", port=8000)

Contributing

Contributions are welcome!
Please open an issue or submit a pull request.


License

Distributed under the MIT License.
See the LICENSE file for more information.

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

fastapi_opinionated_core-0.1.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

fastapi_opinionated_core-0.1.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_opinionated_core-0.1.1.tar.gz.

File metadata

  • Download URL: fastapi_opinionated_core-0.1.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for fastapi_opinionated_core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f035fe13b627e42b83f6ec213b0f5a00c8b2e04aabaadbe403894fac91358559
MD5 cf35641c486703aa7a69539ad020851d
BLAKE2b-256 0cf3f913f8145a832b1a4878995cfa39fc717f3abf5f2f542b4b1c0dbb8d72d0

See more details on using hashes here.

File details

Details for the file fastapi_opinionated_core-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_opinionated_core-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 499d783eafe49db2e2cb7d5231f21066709a46b168b01fbabf56d947fdf663f7
MD5 b67117d1c2638e807f0b9118d05c3371
BLAKE2b-256 f22a3ee7547aab46ea6501e917cf71117eb516c6bde72d61b34512c7d504e5d3

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