Libraries and Dependencies - csed-ucm/psephos GitHub Wiki

Libraries and Dependencies

This document lists the libraries used in the Psephos project with descriptions, use cases, and examples.

Backend Development Libraries

FastAPI

FastAPI is a modern, high-performance web framework for building APIs with Python.

Why FastAPI:

  • Built-in async/await support for high performance
  • Automatic API documentation generation (OpenAPI/Swagger)
  • Type hints integration with Pydantic
  • Built-in request validation and serialization
  • Excellent developer experience

Usage in Project:

  • Main web framework for API endpoints
  • Request/response handling
  • Dependency injection system
  • WebSocket support

Pydantic

Data validation and settings management using Python type annotations.

Features:

  • Runtime type checking and validation
  • Automatic data conversion
  • JSON schema generation
  • Settings management from environment variables

Usage in Project:

  • Request/response schemas
  • Configuration management
  • Database model validation
  • Type safety throughout the application

Beanie

Asynchronous Python Object-Document Mapper (ODM) for MongoDB.

Features:

  • Built on top of Motor (async MongoDB driver)
  • Pydantic-based document models
  • Query builder with type hints
  • Automatic indexing and validation

Usage in Project:

  • Database document definitions
  • CRUD operations
  • Relationship management
  • Query optimization

FastAPI Users

Authentication and user management framework for FastAPI.

Features:

  • Multiple authentication backends (JWT, OAuth, etc.)
  • User registration and management
  • Password reset functionality
  • Superuser support

Usage in Project:

  • JWT token authentication
  • User registration and login
  • Password management
  • Role-based access control

Testing Libraries

Pytest

Modern testing framework for Python applications.

Features:

  • Simple test writing with assert statements
  • Powerful fixtures system
  • Parallel test execution
  • Plugin ecosystem

Usage in Project:

def test_create_workspace(client, auth_headers):
    response = client.post(
        "/workspaces",
        json={"name": "Test Workspace", "description": "Test"},
        headers=auth_headers
    )
    assert response.status_code == 201
    assert response.json()["name"] == "Test Workspace"

Pytest Coverage

Coverage reporting for pytest.

Usage:

pytest --cov=app --cov-report=html

Flake8

Python linting tool for code style enforcement.

Configuration in pyproject.toml:

[tool.flake8]
max-line-length = 120
exclude = [".git", "__pycache__", "build", "dist"]

MyPy

Static type checker for Python.

Configuration:

[tool.mypy]
python_version = "3.11"
plugins = ["pydantic.mypy"]
ignore_missing_imports = true

Tox

Test automation and virtual environment management.

Usage:

  • Tests multiple Python versions
  • Runs linting and type checking
  • Ensures consistent testing environment

Faker

Library for generating fake data for testing.

Usage:

from faker import Faker

fake = Faker()
test_user = {
    "email": fake.email(),
    "first_name": fake.first_name(),
    "last_name": fake.last_name()
}

Production Libraries

Uvicorn

ASGI web server implementation for Python.

Features:

  • High performance async server
  • HTTP/1.1 and WebSocket support
  • Development auto-reload
  • Production-ready

Usage:

uvicorn app.app:app --host 0.0.0.0 --port 8000 --reload

Gunicorn

Python WSGI HTTP Server for UNIX.

Features:

  • Process management
  • Load balancing
  • Worker process management
  • Production deployment

Usage with Uvicorn workers:

gunicorn app.app:app -w 4 -k uvicorn.workers.UvicornWorker

Database and Storage

Motor

Asynchronous Python driver for MongoDB.

Features:

  • Async/await support
  • Connection pooling
  • GridFS support
  • Compatible with asyncio

MongoDB

NoSQL document database.

Why MongoDB:

  • Flexible schema for evolving data models
  • Built-in horizontal scaling
  • Rich query language
  • Strong consistency options

Development Tools

setuptools

Python package development and distribution.

Usage:

  • Package building and installation
  • Dependency management
  • Entry point definitions

Build

PEP 517 build frontend for Python packages.

Usage:

python -m build .

CLI and Utilities

Click / Typer

Command-line interface creation.

Usage in Project:

  • CLI commands for server management
  • Configuration setup wizard
  • Development utilities

Colorama

Cross-platform colored terminal text.

Usage:

from colorama import Fore, Style

print(f"{Fore.GREEN}Success:{Style.RESET_ALL} Operation completed")

Security

PyJWT

JSON Web Token implementation for Python.

Features:

  • Token encoding/decoding
  • Multiple algorithms support
  • Key management

Passlib

Password hashing library.

Features:

  • Multiple hashing algorithms
  • Salt generation
  • Password verification

Configuration Management

python-dotenv

Environment variable loading from .env files.

Usage:

from dotenv import load_dotenv
load_dotenv()

This library ecosystem provides a robust foundation for building, testing, and deploying the Psephos API with modern Python development practices.