Skip to main content

No project description provided

Project description

FastModule

Mini tool to create FastAPI applications with a basic project structure inspired by Nest.js

Installation

Create a virtual enviroment (Optional)

python -m venv venv
source venv/bin/activate # venv/Scripts/activate on Windows

Install package (require python ^3.10 version)

pip install fastmodule

Example

Create a controller file and add the following code:

from fastmodule.common import Controller, Get, Post
from pydantic import BaseModel

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

@Controller('users')
class UserController:

    @Get('/')
    def find_all(self) -> str:
        return 'This action returns all users'
    
    @Get('/{id}')
    def find_one(self, id: int) -> str:
        return f'This action returns one user with id {id}'

    @Post('/')
    def create(self, user: User) -> str:
        return f'This action create a user with data {user}'

Add the controller in the main file

Add in the main file:

from fastmodule import FastModule
from src.user_controller import UserController

app = FastModule()

app.include_router(UserController().router)

Run the application:

uvicorn main:app --port 8000

Open docs in the browser at localhost:8000/docs:

plot

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

fastmodule-0.0.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

fastmodule-0.0.1-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page