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:
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
fastmodule-0.0.1.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for fastmodule-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8f51eb755102972b7f71900fdd95e30799a0d1ec5d2fa5081307e121457ec6a |
|
MD5 | b0fea033bac76436b0811ae5ffac34a8 |
|
BLAKE2b-256 | 7e21d7f1633885724acf593156999cab0589cabb35a45fd2720302c9d4bffa23 |