Skip to main content

8 posts tagged with "fastapi"

fastapi tag description

View All Tags

Python Annotations Rare Use Cases

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Python annotations, introduced in PEP 3107 for function parameters and return values, were initially generic metadata slots. While their primary use has become type hinting (PEP 484), expert developers leverage them for advanced and niche applications that go far beyond simple type declarations.

These use cases often involve frameworks or metaprogramming to make annotations act as declarative configuration or runtime execution instructions.

FastAPI Core Middleware Examples and Use Cases

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Middleware in FastAPI (which is built on Starlette) is a powerful mechanism for executing code before and after a request is processed by the route handler. Middleware allows you to apply logic globally or across a group of routes, such as logging, authentication, CORS, and response manipulation.

The standard way to implement custom middleware is by defining an async function that takes the request and the call_next callable.

FastAPI Dependency Injection: Internal Requests, Request Object, and Parameterized Depends

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

FastAPI's Dependency Injection (DI) system is one of its most powerful architectural features. It allows developers to encapsulate authentication, parameter validation, database sessions, and low-level HTTP inspection into reusable, composable units.

This guide provides a comprehensive manual on advanced FastAPI dependency injection patterns: executing in-process internal route requests with TestClient, parameterizing dependencies with factories, accessing the Starlette Request object, nesting dependency resolution chains, and leveraging class-based dependencies.

FastAPI Dependency Injection: The Complete Guide from Basics to Advanced Patterns

9 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Dependency Injection (DI) is one of the core architectural design choices that makes FastAPI so powerful. It handles cross-cutting concerns-such as database connections, security, authentication, and request parsing-with minimal boilerplate.

Whether you are a beginner looking to understand the Depends syntax or an expert building complex authorization layers and mockable tests, this guide covers everything you need to master FastAPI's dependency injection system.

Benchmark & Architecture Guide: msgspec vs. Pydantic v2

6 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

High-throughput Python microservices, data ingestion pipelines, and web APIs frequently bottleneck on serialization and data validation. While Pydantic v2 (re-written with a Rust core) revolutionized Python data validation, msgspec offers extreme performance advantages for specialized data workloads.

This guide provides a comprehensive benchmark analysis and architectural breakdown comparing msgspec and Pydantic v2, detailing throughput metrics, validation mechanics, ecosystem trade-offs, and selection criteria.

Msgspec FastAPI Integration: High Performance, Validation, and OpenAPI Docs

5 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

msgspec is a Python library designed for high-performance serialization and validation, which makes it a powerful partner for FastAPI. It can be used as a drop-in replacement for FastAPI's default Pydantic models to handle data validation and schema generation, often leading to a significant speedup in API performance.

How to Measure Execution Time in Python: Vanilla Python, FastAPI, Flask, and Django

8 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Measuring how long your Python code takes to run is a critical skill for performance optimization, benchmarking, and identifying bottlenecks in production applications. Depending on whether you are analyzing a single micro-operation, profiling a complex function, or tracking HTTP request-response lifecycles, Python offers a wide variety of tools.

This guide provides a comprehensive breakdown of how to measure execution time in vanilla Python, followed by specialized implementations for the three major web frameworks: FastAPI, Flask, and Django.

How to Connect and Integrate Supabase with Python: FastAPI, Flask, and Django

8 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Supabase is a popular PostgreSQL-based BaaS (Backend-as-a-Service). Because it runs on a standard PostgreSQL database, you can connect to it using traditional database drivers (like psycopg2 or SQLAlchemy) or leverage its built-in REST API using client SDKs.

This guide provides a comprehensive walkthrough for integrating Supabase into your Python web applications, detailing implementations for FastAPI, Flask, and Django.