Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,7 @@ coverage.xml
.mypy_cache/

# .key
SECRET.key
SECRET.key

# poetry lock
poetry.lock
150 changes: 149 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div align="center">
<img src="images/python_logo.png" alt="Logo" width="80" height="80">

<h3 align="center">Python Fast API boilerplate</h3>
<h3 align="center">Product Fast API boilerplate</h3>

<p align="center">
Fast API boiler plate project
Expand Down Expand Up @@ -151,6 +151,154 @@ Requirement of Project
alembic downgrade -1
```

# Poetry Installation Guide

This guide provides detailed instructions on how to set up and use [Poetry](https://python-poetry.org/) for managing dependencies and environments in your Python project.

## What is Poetry?

Poetry is a dependency management and packaging tool for Python. It simplifies the process of managing project dependencies, virtual environments, and publishing packages.

Key features:
- Dependency resolution.
- Virtual environment management.
- Project packaging and publishing.

## Prerequisites

- **Python**: Ensure Python is installed on your system. Poetry supports Python 3.7 and above.
- **Pip**: The Python package manager should also be installed.

You can verify installations using the following commands:
```bash
python --version
pip --version
```

## Installing Poetry

### 1. Using the Official Installer

Run the following command to install Poetry:

```bash
curl -sSL https://install.python-poetry.org | python3 -
```

### 2. Verifying Installation

Once installed, verify Poetry by running:

```bash
poetry --version
```

This should display the installed version of Poetry.

### 3. Adding Poetry to Your PATH

If Poetry is not recognized, ensure it is added to your system PATH. By default, Poetry is installed in:
- **Unix/macOS**: `$HOME/.local/bin`
- **Windows**: `%APPDATA%\Python\Scripts`

Add this directory to your PATH.

## Setting Up Poetry in a Project

### 1. Initialize a New Project

Navigate to your project directory and run:

```bash
poetry init
```

Follow the prompts to define your project metadata (e.g., package name, version, description).

### 2. Adding Dependencies

To add dependencies:

```bash
poetry add <package-name>
```

Example:

```bash
poetry add requests
```

To add development dependencies:

```bash
poetry add --dev <package-name>
```

### 3. Installing Dependencies

Install all dependencies defined in `pyproject.toml`:

```bash
poetry install
```

### 4. Using Virtual Environments

Poetry automatically creates a virtual environment for your project. To activate it:

```bash
poetry shell
```

To deactivate, simply exit the shell:

```bash
exit
```

## Managing Your Project

### Updating Dependencies

To update dependencies to their latest compatible versions:

```bash
poetry update
```

### Listing Installed Packages

To list all installed packages and their versions:

```bash
poetry show
```

### Publishing Your Package

If you’re packaging your project, publish it to PyPI with:

```bash
poetry publish --build
```

## Uninstalling Poetry

To uninstall Poetry, remove its files:

```bash
curl -sSL https://install.python-poetry.org | python3 - --uninstall
```

## Additional Resources

- [Poetry Documentation](https://python-poetry.org/docs/)
- [Poetry GitHub Repository](https://github.com/python-poetry/poetry)

With this setup, you can efficiently manage Python project dependencies and environments using Poetry. Happy coding!


## Run the server in development mode

Add environment variables (given in .env) by running following command in cmd/terminal:
Expand Down
23 changes: 17 additions & 6 deletions apps/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
from fastapi.responses import JSONResponse

# from core.config import config
from middleware.response_log_middleware import ResponseLogMiddleware
from middleware.rate_limiting_middleware import RateLimitMiddleware
from apps.v1.api.auth.view import authrouter
from config import project_path, LoggingConfig
from core import CustomException
from core.utils import constant_variable
from middleware import S3PathMiddleware


def init_routers(app_: FastAPI) -> None:
pass
# app_.include_router(user_router)
app_.include_router(
authrouter, prefix=f"{constant_variable.API_V1}/auth", tags=["Authentication"]
)


def init_listeners(app_: FastAPI) -> None:
Expand All @@ -26,8 +30,7 @@ async def custom_exception_handler(request: Request, exc: CustomException):
status_code=exc.status,
content=content,
)



def make_middleware() -> list[Middleware]:
middleware = [
Middleware(
Expand All @@ -40,6 +43,14 @@ def make_middleware() -> list[Middleware]:
Middleware(
S3PathMiddleware, config_path=f"{project_path.S3_ROOT}/s3_paths_config.json"
),
Middleware(
ResponseLogMiddleware
),
Middleware(
RateLimitMiddleware,
rate_limit=constant_variable.RATE_LIMIT,
time_window=constant_variable.TIME_WINDOW
)
]
return middleware

Expand All @@ -49,8 +60,8 @@ def make_middleware() -> list[Middleware]:

def create_app() -> FastAPI:
app_ = FastAPI(
title="Hide",
description="Hide API",
title="VC_Product Fastapi Boilerplate",
description="FastAPI",
version="1.0.0",
# docs_url=None if config.ENV == "production" else "/docs",
# redoc_url=None if config.ENV == "production" else "/redoc",
Expand Down
8 changes: 8 additions & 0 deletions apps/v1/api/auth/models/attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from core.db.db_attribute import BaseAttributes
from core.utils import constant_variable as constant


class SsoType(BaseAttributes):
google = constant.STATUS_ONE
facebook = constant.STATUS_TWO
apple = constant.STATUS_THREE
51 changes: 40 additions & 11 deletions apps/v1/api/auth/models/methods/method1.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
"""This module contains database operations methods."""
from sqlalchemy.orm import Session

from sqlalchemy.future import select
from sqlalchemy.ext.asyncio import AsyncSession

class UserAuthMethod():

class UserAuthMethod:
"""This class defines methods to authenticate users."""

def __init__(self, model) -> None:
self.model = model

def find_by_email(self, db: Session, email: str):
"""This funtion will return the email object"""
return db.query(self.model).filter(
self.model.email == email
).first()
async def find_by_email(self, db: AsyncSession, email: str):
"""This function will return the user object by email asynchronously."""
async with db: # Ensure the session context
stmt = select(self.model).where(self.model.email == email)
result = await db.execute(stmt)
return result.scalars().first()

async def find_by_username(self, db: AsyncSession, username: str):
"""This function will return the username object"""
async with db: # Ensure the session context
stmt = select(self.model).where(self.model.username == username)
result = await db.execute(stmt)
return result.scalars().first()

async def find_user_by_otp_referenceId(
self, db: AsyncSession, otp_referenceId: str
):
"""This function will return the username object"""
async with db: # Ensure the session context
stmt = select(self.model).where(
self.model.otp_referenceId == otp_referenceId
)
result = await db.execute(stmt)
return result.scalars().first()

async def find_verified_phone_user(self, db: AsyncSession, phone: str):
"""This function will return the username object"""
async with db: # Ensure the session context
stmt = select(self.model).where(self.model.phone == phone)
result = await db.execute(stmt)
return result.scalars().first()

def find_by_username(self, db: Session, username: str):
async def find_verified_email_user(self, db: AsyncSession, email: str):
"""This function will return the username object"""
return db.query(self.model).filter(
self.model.username == username
).first()
async with db: # Ensure the session context
stmt = select(self.model).where(self.model.email == email)
result = await db.execute(stmt)
return result.scalars().first()
Loading