fastapi-mongo-setup 0.3.2__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastapi_mongo_setup-0.4.0/PKG-INFO +115 -0
- fastapi_mongo_setup-0.4.0/README.md +101 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/pyproject.toml +1 -1
- fastapi_mongo_setup-0.4.0/src/auth/__init__.py +0 -0
- fastapi_mongo_setup-0.4.0/src/auth/dependencies.py +35 -0
- fastapi_mongo_setup-0.4.0/src/auth/router.py +32 -0
- fastapi_mongo_setup-0.4.0/src/auth/schemas.py +19 -0
- fastapi_mongo_setup-0.4.0/src/auth/service.py +22 -0
- fastapi_mongo_setup-0.4.0/src/auth/utils.py +11 -0
- fastapi_mongo_setup-0.4.0/src/fastapi_mongo_setup.egg-info/PKG-INFO +115 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/fastapi_mongo_setup.egg-info/SOURCES.txt +6 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/fastapi_mongo_setup.egg-info/top_level.txt +1 -0
- fastapi_mongo_setup-0.4.0/src/mongo_setup/cli.py +509 -0
- fastapi_mongo_setup-0.3.2/PKG-INFO +0 -82
- fastapi_mongo_setup-0.3.2/README.md +0 -68
- fastapi_mongo_setup-0.3.2/src/fastapi_mongo_setup.egg-info/PKG-INFO +0 -82
- fastapi_mongo_setup-0.3.2/src/mongo_setup/cli.py +0 -238
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/setup.cfg +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/fastapi_mongo_setup.egg-info/dependency_links.txt +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/fastapi_mongo_setup.egg-info/entry_points.txt +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/fastapi_mongo_setup.egg-info/requires.txt +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/mongo_setup/__init__.py +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/tasks/router.py +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/tasks/schemas.py +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/tasks/service.py +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/utils/db.py +0 -0
- {fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/utils/helpers.py +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-mongo-setup
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: A CLI tool to auto-generate MongoDB connection boilerplates for FastAPI projects.
|
|
5
|
+
Author-email: Souvik <wbjee.souvik@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Souvik6222/fastapi-mongo-setup
|
|
7
|
+
Project-URL: Issues, https://github.com/Souvik6222/fastapi-mongo-setup/issues
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: motor
|
|
11
|
+
Requires-Dist: python-dotenv
|
|
12
|
+
Requires-Dist: fastapi
|
|
13
|
+
Requires-Dist: pydantic-settings
|
|
14
|
+
|
|
15
|
+
# fastapi-mongo-setup 🚀
|
|
16
|
+
|
|
17
|
+
[](https://badge.fury.io/py/fastapi-mongo-setup)
|
|
18
|
+
[](https://pypi.python.org/pypi/fastapi-mongo-setup)
|
|
19
|
+
[](https://opensource.org/licenses/MIT)
|
|
20
|
+
|
|
21
|
+
**Stop writing MongoDB boilerplate for FastAPI!**
|
|
22
|
+
`fastapi-mongo-setup` is a fast, lightweight Python CLI tool that instantly scaffolds a professional, industry-standard FastAPI + MongoDB project structure — including an optional **JWT authentication system**.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## ⚡ Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install fastapi-mongo-setup
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 🛠️ Usage
|
|
33
|
+
|
|
34
|
+
### Basic Setup (DB + CRUD)
|
|
35
|
+
Navigate to your project folder and run:
|
|
36
|
+
```bash
|
|
37
|
+
mongo-setup
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### With Authentication 🔐
|
|
41
|
+
Add a complete JWT auth system (register, login, protected routes):
|
|
42
|
+
```bash
|
|
43
|
+
mongo-setup --auth
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 📁 Generated Project Structure
|
|
49
|
+
|
|
50
|
+
### Without `--auth`
|
|
51
|
+
```text
|
|
52
|
+
your-project/
|
|
53
|
+
├── .env # MONGODB_URL, DATABASE_NAME, PORT
|
|
54
|
+
├── requirements.txt # fastapi, motor, pydantic-settings, etc.
|
|
55
|
+
├── main.py # FastAPI entry point with MongoDB lifespan
|
|
56
|
+
└── src/
|
|
57
|
+
├── config.py # Pydantic Settings configuration loader
|
|
58
|
+
├── utils/
|
|
59
|
+
│ ├── db.py # Async Motor connection manager
|
|
60
|
+
│ └── helpers.py # ObjectId serialization helpers
|
|
61
|
+
└── tasks/
|
|
62
|
+
├── router.py # GET / POST / DELETE endpoints
|
|
63
|
+
├── schemas.py # Pydantic validation models
|
|
64
|
+
└── service.py # Database CRUD logic
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### With `--auth` (adds these files)
|
|
68
|
+
```text
|
|
69
|
+
└── src/
|
|
70
|
+
├── config.py # Now includes SECRET_KEY, ALGORITHM, etc.
|
|
71
|
+
└── auth/ # 🔐 Complete Auth Module
|
|
72
|
+
├── router.py # /auth/register, /auth/login, /auth/me
|
|
73
|
+
├── schemas.py # UserCreate, UserLogin, Token models
|
|
74
|
+
├── service.py # Create user, find user by email
|
|
75
|
+
├── dependencies.py # JWT creation & verification, get_current_user
|
|
76
|
+
└── utils.py # Password hashing with bcrypt
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Plus auto-updates to:
|
|
80
|
+
- **`.env`** → adds `SECRET_KEY`, `ALGORITHM`, `ACCESS_TOKEN_EXPIRE_MINUTES`
|
|
81
|
+
- **`requirements.txt`** → adds `python-jose`, `passlib`, `bcrypt`
|
|
82
|
+
- **`main.py`** → registers the auth router automatically
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 🚀 Running Your Generated Project
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# 1. Install dependencies
|
|
90
|
+
pip install -r requirements.txt
|
|
91
|
+
|
|
92
|
+
# 2. Start the server
|
|
93
|
+
python main.py
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Open `http://localhost:8000/docs` to see your Swagger UI with fully functional **Tasks CRUD** and (if `--auth` was used) **Authentication** endpoints!
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 🔐 Auth Endpoints (when using `--auth`)
|
|
101
|
+
|
|
102
|
+
| Method | Endpoint | Description | Auth Required |
|
|
103
|
+
|--------|-------------------|--------------------------------|---------------|
|
|
104
|
+
| POST | `/auth/register` | Create a new user account | ❌ |
|
|
105
|
+
| POST | `/auth/login` | Get a JWT access token | ❌ |
|
|
106
|
+
| GET | `/auth/me` | Get current user's profile | ✅ Bearer |
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 🏗 Why this exists?
|
|
111
|
+
|
|
112
|
+
Setting up `Motor` (async MongoDB driver) with FastAPI typically requires repetitive boilerplate: connection managers, lifespans, ObjectId serialization, and JWT auth plumbing. This tool does all of that for you in **one command**, providing a clean, modular architecture designed for scaling.
|
|
113
|
+
|
|
114
|
+
## 🤝 Contributing
|
|
115
|
+
Found a bug or want to request a feature? Feel free to [open an issue](https://github.com/Souvik6222/fastapi-mongo-setup/issues) or submit a pull request!
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# fastapi-mongo-setup 🚀
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/fastapi-mongo-setup)
|
|
4
|
+
[](https://pypi.python.org/pypi/fastapi-mongo-setup)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**Stop writing MongoDB boilerplate for FastAPI!**
|
|
8
|
+
`fastapi-mongo-setup` is a fast, lightweight Python CLI tool that instantly scaffolds a professional, industry-standard FastAPI + MongoDB project structure — including an optional **JWT authentication system**.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## ⚡ Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install fastapi-mongo-setup
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 🛠️ Usage
|
|
19
|
+
|
|
20
|
+
### Basic Setup (DB + CRUD)
|
|
21
|
+
Navigate to your project folder and run:
|
|
22
|
+
```bash
|
|
23
|
+
mongo-setup
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### With Authentication 🔐
|
|
27
|
+
Add a complete JWT auth system (register, login, protected routes):
|
|
28
|
+
```bash
|
|
29
|
+
mongo-setup --auth
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 📁 Generated Project Structure
|
|
35
|
+
|
|
36
|
+
### Without `--auth`
|
|
37
|
+
```text
|
|
38
|
+
your-project/
|
|
39
|
+
├── .env # MONGODB_URL, DATABASE_NAME, PORT
|
|
40
|
+
├── requirements.txt # fastapi, motor, pydantic-settings, etc.
|
|
41
|
+
├── main.py # FastAPI entry point with MongoDB lifespan
|
|
42
|
+
└── src/
|
|
43
|
+
├── config.py # Pydantic Settings configuration loader
|
|
44
|
+
├── utils/
|
|
45
|
+
│ ├── db.py # Async Motor connection manager
|
|
46
|
+
│ └── helpers.py # ObjectId serialization helpers
|
|
47
|
+
└── tasks/
|
|
48
|
+
├── router.py # GET / POST / DELETE endpoints
|
|
49
|
+
├── schemas.py # Pydantic validation models
|
|
50
|
+
└── service.py # Database CRUD logic
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### With `--auth` (adds these files)
|
|
54
|
+
```text
|
|
55
|
+
└── src/
|
|
56
|
+
├── config.py # Now includes SECRET_KEY, ALGORITHM, etc.
|
|
57
|
+
└── auth/ # 🔐 Complete Auth Module
|
|
58
|
+
├── router.py # /auth/register, /auth/login, /auth/me
|
|
59
|
+
├── schemas.py # UserCreate, UserLogin, Token models
|
|
60
|
+
├── service.py # Create user, find user by email
|
|
61
|
+
├── dependencies.py # JWT creation & verification, get_current_user
|
|
62
|
+
└── utils.py # Password hashing with bcrypt
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Plus auto-updates to:
|
|
66
|
+
- **`.env`** → adds `SECRET_KEY`, `ALGORITHM`, `ACCESS_TOKEN_EXPIRE_MINUTES`
|
|
67
|
+
- **`requirements.txt`** → adds `python-jose`, `passlib`, `bcrypt`
|
|
68
|
+
- **`main.py`** → registers the auth router automatically
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 🚀 Running Your Generated Project
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# 1. Install dependencies
|
|
76
|
+
pip install -r requirements.txt
|
|
77
|
+
|
|
78
|
+
# 2. Start the server
|
|
79
|
+
python main.py
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Open `http://localhost:8000/docs` to see your Swagger UI with fully functional **Tasks CRUD** and (if `--auth` was used) **Authentication** endpoints!
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 🔐 Auth Endpoints (when using `--auth`)
|
|
87
|
+
|
|
88
|
+
| Method | Endpoint | Description | Auth Required |
|
|
89
|
+
|--------|-------------------|--------------------------------|---------------|
|
|
90
|
+
| POST | `/auth/register` | Create a new user account | ❌ |
|
|
91
|
+
| POST | `/auth/login` | Get a JWT access token | ❌ |
|
|
92
|
+
| GET | `/auth/me` | Get current user's profile | ✅ Bearer |
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 🏗 Why this exists?
|
|
97
|
+
|
|
98
|
+
Setting up `Motor` (async MongoDB driver) with FastAPI typically requires repetitive boilerplate: connection managers, lifespans, ObjectId serialization, and JWT auth plumbing. This tool does all of that for you in **one command**, providing a clean, modular architecture designed for scaling.
|
|
99
|
+
|
|
100
|
+
## 🤝 Contributing
|
|
101
|
+
Found a bug or want to request a feature? Feel free to [open an issue](https://github.com/Souvik6222/fastapi-mongo-setup/issues) or submit a pull request!
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "fastapi-mongo-setup"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "A CLI tool to auto-generate MongoDB connection boilerplates for FastAPI projects."
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Souvik", email = "wbjee.souvik@gmail.com"},
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from datetime import datetime, timedelta
|
|
2
|
+
from jose import JWTError, jwt
|
|
3
|
+
from fastapi import Depends, HTTPException, status
|
|
4
|
+
from fastapi.security import OAuth2PasswordBearer
|
|
5
|
+
from src.config import settings
|
|
6
|
+
from src.auth.service import AuthService
|
|
7
|
+
from src.utils.helpers import serialize_doc
|
|
8
|
+
|
|
9
|
+
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")
|
|
10
|
+
|
|
11
|
+
def create_access_token(data: dict) -> str:
|
|
12
|
+
"""Create a JWT access token with an expiration time."""
|
|
13
|
+
to_encode = data.copy()
|
|
14
|
+
expire = datetime.utcnow() + timedelta(minutes=settings.access_token_expire_minutes)
|
|
15
|
+
to_encode.update({"exp": expire})
|
|
16
|
+
return jwt.encode(to_encode, settings.secret_key, algorithm=settings.algorithm)
|
|
17
|
+
|
|
18
|
+
async def get_current_user(token: str = Depends(oauth2_scheme)):
|
|
19
|
+
"""Decode the JWT token and return the current user from the database."""
|
|
20
|
+
credentials_exception = HTTPException(
|
|
21
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
22
|
+
detail="Could not validate credentials",
|
|
23
|
+
headers={"WWW-Authenticate": "Bearer"},
|
|
24
|
+
)
|
|
25
|
+
try:
|
|
26
|
+
payload = jwt.decode(token, settings.secret_key, algorithms=[settings.algorithm])
|
|
27
|
+
email: str = payload.get("sub")
|
|
28
|
+
if email is None:
|
|
29
|
+
raise credentials_exception
|
|
30
|
+
except JWTError:
|
|
31
|
+
raise credentials_exception
|
|
32
|
+
user = await AuthService.get_user_by_email(email)
|
|
33
|
+
if user is None:
|
|
34
|
+
raise credentials_exception
|
|
35
|
+
return serialize_doc(user)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from fastapi import APIRouter, HTTPException, Depends
|
|
2
|
+
from src.auth.schemas import UserCreate, UserLogin, UserResponse, Token
|
|
3
|
+
from src.auth.service import AuthService
|
|
4
|
+
from src.auth.dependencies import create_access_token, get_current_user
|
|
5
|
+
from src.auth.utils import verify_password
|
|
6
|
+
|
|
7
|
+
router = APIRouter(prefix="/auth", tags=["Authentication"])
|
|
8
|
+
|
|
9
|
+
@router.post("/register", response_model=UserResponse)
|
|
10
|
+
async def register(user: UserCreate):
|
|
11
|
+
"""Register a new user account."""
|
|
12
|
+
existing_user = await AuthService.get_user_by_email(user.email)
|
|
13
|
+
if existing_user:
|
|
14
|
+
raise HTTPException(status_code=400, detail="Email already registered")
|
|
15
|
+
created_user = await AuthService.create_user(user.model_dump())
|
|
16
|
+
return created_user
|
|
17
|
+
|
|
18
|
+
@router.post("/login", response_model=Token)
|
|
19
|
+
async def login(user: UserLogin):
|
|
20
|
+
"""Authenticate user and return a JWT access token."""
|
|
21
|
+
db_user = await AuthService.get_user_by_email(user.email)
|
|
22
|
+
if not db_user:
|
|
23
|
+
raise HTTPException(status_code=401, detail="Invalid credentials")
|
|
24
|
+
if not verify_password(user.password, db_user["password"]):
|
|
25
|
+
raise HTTPException(status_code=401, detail="Invalid credentials")
|
|
26
|
+
access_token = create_access_token(data={"sub": db_user["email"]})
|
|
27
|
+
return {"access_token": access_token, "token_type": "bearer"}
|
|
28
|
+
|
|
29
|
+
@router.get("/me", response_model=UserResponse)
|
|
30
|
+
async def get_me(current_user: dict = Depends(get_current_user)):
|
|
31
|
+
"""Get the profile of the currently authenticated user."""
|
|
32
|
+
return current_user
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
|
|
3
|
+
class UserCreate(BaseModel):
|
|
4
|
+
name: str = Field(..., example="John Doe")
|
|
5
|
+
email: str = Field(..., example="john@example.com")
|
|
6
|
+
password: str = Field(..., min_length=6, example="secret123")
|
|
7
|
+
|
|
8
|
+
class UserLogin(BaseModel):
|
|
9
|
+
email: str = Field(..., example="john@example.com")
|
|
10
|
+
password: str = Field(..., example="secret123")
|
|
11
|
+
|
|
12
|
+
class UserResponse(BaseModel):
|
|
13
|
+
id: str
|
|
14
|
+
name: str
|
|
15
|
+
email: str
|
|
16
|
+
|
|
17
|
+
class Token(BaseModel):
|
|
18
|
+
access_token: str
|
|
19
|
+
token_type: str = "bearer"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from src.utils.db import db
|
|
2
|
+
from src.utils.helpers import serialize_doc
|
|
3
|
+
from src.auth.utils import hash_password
|
|
4
|
+
|
|
5
|
+
class AuthService:
|
|
6
|
+
@staticmethod
|
|
7
|
+
def get_collection():
|
|
8
|
+
return db.db["users"]
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
async def create_user(user_data: dict) -> dict:
|
|
12
|
+
"""Hash password and insert user into the database."""
|
|
13
|
+
user_data["password"] = hash_password(user_data["password"])
|
|
14
|
+
result = await AuthService.get_collection().insert_one(user_data)
|
|
15
|
+
created_user = await AuthService.get_collection().find_one({"_id": result.inserted_id})
|
|
16
|
+
return serialize_doc(created_user)
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
async def get_user_by_email(email: str):
|
|
20
|
+
"""Find a user document by email address."""
|
|
21
|
+
user = await AuthService.get_collection().find_one({"email": email})
|
|
22
|
+
return user
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from passlib.context import CryptContext
|
|
2
|
+
|
|
3
|
+
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
4
|
+
|
|
5
|
+
def hash_password(password: str) -> str:
|
|
6
|
+
"""Hash a plain-text password using bcrypt."""
|
|
7
|
+
return pwd_context.hash(password)
|
|
8
|
+
|
|
9
|
+
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
|
10
|
+
"""Verify a plain-text password against its hash."""
|
|
11
|
+
return pwd_context.verify(plain_password, hashed_password)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-mongo-setup
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: A CLI tool to auto-generate MongoDB connection boilerplates for FastAPI projects.
|
|
5
|
+
Author-email: Souvik <wbjee.souvik@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Souvik6222/fastapi-mongo-setup
|
|
7
|
+
Project-URL: Issues, https://github.com/Souvik6222/fastapi-mongo-setup/issues
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: motor
|
|
11
|
+
Requires-Dist: python-dotenv
|
|
12
|
+
Requires-Dist: fastapi
|
|
13
|
+
Requires-Dist: pydantic-settings
|
|
14
|
+
|
|
15
|
+
# fastapi-mongo-setup 🚀
|
|
16
|
+
|
|
17
|
+
[](https://badge.fury.io/py/fastapi-mongo-setup)
|
|
18
|
+
[](https://pypi.python.org/pypi/fastapi-mongo-setup)
|
|
19
|
+
[](https://opensource.org/licenses/MIT)
|
|
20
|
+
|
|
21
|
+
**Stop writing MongoDB boilerplate for FastAPI!**
|
|
22
|
+
`fastapi-mongo-setup` is a fast, lightweight Python CLI tool that instantly scaffolds a professional, industry-standard FastAPI + MongoDB project structure — including an optional **JWT authentication system**.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## ⚡ Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install fastapi-mongo-setup
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 🛠️ Usage
|
|
33
|
+
|
|
34
|
+
### Basic Setup (DB + CRUD)
|
|
35
|
+
Navigate to your project folder and run:
|
|
36
|
+
```bash
|
|
37
|
+
mongo-setup
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### With Authentication 🔐
|
|
41
|
+
Add a complete JWT auth system (register, login, protected routes):
|
|
42
|
+
```bash
|
|
43
|
+
mongo-setup --auth
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 📁 Generated Project Structure
|
|
49
|
+
|
|
50
|
+
### Without `--auth`
|
|
51
|
+
```text
|
|
52
|
+
your-project/
|
|
53
|
+
├── .env # MONGODB_URL, DATABASE_NAME, PORT
|
|
54
|
+
├── requirements.txt # fastapi, motor, pydantic-settings, etc.
|
|
55
|
+
├── main.py # FastAPI entry point with MongoDB lifespan
|
|
56
|
+
└── src/
|
|
57
|
+
├── config.py # Pydantic Settings configuration loader
|
|
58
|
+
├── utils/
|
|
59
|
+
│ ├── db.py # Async Motor connection manager
|
|
60
|
+
│ └── helpers.py # ObjectId serialization helpers
|
|
61
|
+
└── tasks/
|
|
62
|
+
├── router.py # GET / POST / DELETE endpoints
|
|
63
|
+
├── schemas.py # Pydantic validation models
|
|
64
|
+
└── service.py # Database CRUD logic
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### With `--auth` (adds these files)
|
|
68
|
+
```text
|
|
69
|
+
└── src/
|
|
70
|
+
├── config.py # Now includes SECRET_KEY, ALGORITHM, etc.
|
|
71
|
+
└── auth/ # 🔐 Complete Auth Module
|
|
72
|
+
├── router.py # /auth/register, /auth/login, /auth/me
|
|
73
|
+
├── schemas.py # UserCreate, UserLogin, Token models
|
|
74
|
+
├── service.py # Create user, find user by email
|
|
75
|
+
├── dependencies.py # JWT creation & verification, get_current_user
|
|
76
|
+
└── utils.py # Password hashing with bcrypt
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Plus auto-updates to:
|
|
80
|
+
- **`.env`** → adds `SECRET_KEY`, `ALGORITHM`, `ACCESS_TOKEN_EXPIRE_MINUTES`
|
|
81
|
+
- **`requirements.txt`** → adds `python-jose`, `passlib`, `bcrypt`
|
|
82
|
+
- **`main.py`** → registers the auth router automatically
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 🚀 Running Your Generated Project
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# 1. Install dependencies
|
|
90
|
+
pip install -r requirements.txt
|
|
91
|
+
|
|
92
|
+
# 2. Start the server
|
|
93
|
+
python main.py
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Open `http://localhost:8000/docs` to see your Swagger UI with fully functional **Tasks CRUD** and (if `--auth` was used) **Authentication** endpoints!
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 🔐 Auth Endpoints (when using `--auth`)
|
|
101
|
+
|
|
102
|
+
| Method | Endpoint | Description | Auth Required |
|
|
103
|
+
|--------|-------------------|--------------------------------|---------------|
|
|
104
|
+
| POST | `/auth/register` | Create a new user account | ❌ |
|
|
105
|
+
| POST | `/auth/login` | Get a JWT access token | ❌ |
|
|
106
|
+
| GET | `/auth/me` | Get current user's profile | ✅ Bearer |
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 🏗 Why this exists?
|
|
111
|
+
|
|
112
|
+
Setting up `Motor` (async MongoDB driver) with FastAPI typically requires repetitive boilerplate: connection managers, lifespans, ObjectId serialization, and JWT auth plumbing. This tool does all of that for you in **one command**, providing a clean, modular architecture designed for scaling.
|
|
113
|
+
|
|
114
|
+
## 🤝 Contributing
|
|
115
|
+
Found a bug or want to request a feature? Feel free to [open an issue](https://github.com/Souvik6222/fastapi-mongo-setup/issues) or submit a pull request!
|
{fastapi_mongo_setup-0.3.2 → fastapi_mongo_setup-0.4.0}/src/fastapi_mongo_setup.egg-info/SOURCES.txt
RENAMED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
README.md
|
|
2
2
|
pyproject.toml
|
|
3
|
+
src/auth/__init__.py
|
|
4
|
+
src/auth/dependencies.py
|
|
5
|
+
src/auth/router.py
|
|
6
|
+
src/auth/schemas.py
|
|
7
|
+
src/auth/service.py
|
|
8
|
+
src/auth/utils.py
|
|
3
9
|
src/fastapi_mongo_setup.egg-info/PKG-INFO
|
|
4
10
|
src/fastapi_mongo_setup.egg-info/SOURCES.txt
|
|
5
11
|
src/fastapi_mongo_setup.egg-info/dependency_links.txt
|