Skip to content
tezvyn:

Search

Find a bite, explore a topic or look for a role.

Results for Python

Bites 291

How do you define a Pydantic model for FastAPI request body validation?
Python & FastAPI2 min read

How do you define a Pydantic model for FastAPI request body validation?

Subclass BaseModel with id int, email str, full_name str|None; pass it as a route param so FastAPI validates JSON and returns 422s.

Python & FastAPI2 min read

What standard and code elements power FastAPI's auto-generated API docs?

Tests whether you know FastAPI uses the OpenAPI standard and extracts metadata from Python type hints, Pydantic models, decorators, and docstrings to build interactive docs. Red flag: claiming you must manually maintain a separate schema file.

Python & FastAPI2 min read

How does FastAPI distinguish required optional and default query parameters

Tests whether you know FastAPI infers query parameter optionality from Python signature defaults. Answer: no default means required, Optional[T] = None means optional, T = value sets a default, with all three in one signature.

What is the purpose of @app.get("/") in FastAPI?
Python & FastAPI2 min read

What is the purpose of @app.get("/") in FastAPI?

Tests your understanding of FastAPI routing. A strong answer explains that the decorator binds an HTTP method and path to a Python function, registers it in the app's route table, and builds OpenAPI metadata.

Python & FastAPI2 min read

Write an async decorator that logs execution time for FastAPI

Use functools.wraps, wrap perf_counter around awaited call, log ms, and place decorator above path operation.

Python & FastAPI2 min read

Serialize Pydantic Models with model_dump

model_dump turns a Pydantic model into a plain Python dict, bridging typed objects and JSON serializers in FastAPI endpoints. Call it when you need raw data before returning a response. Do not confuse it with model_dump_json, which emits a string, not a dict.

Most LLM Apps Need Workflows Not Agent Frameworks
MLOps & Infrastructure1 min read

Most LLM Apps Need Workflows Not Agent Frameworks

Most LLM apps ship faster and more reliably as deterministic workflows than autonomous agents. Plain Python with structured outputs and local functions beats CrewAI and LangGraph for debugging. Map control flow in code before importing any agent framework.

Compare Airflow and Kubeflow for ML training pipelines
MLOps & Infrastructure2 min read

Compare Airflow and Kubeflow for ML training pipelines

Tests orchestrator-to-workload fit. Strong answers contrast Airflow's data integration and Python DAGs with Kubeflow's K8s scaling, container reproducibility, and experiment tracking. Red flag: claiming one is always better without stage-specific reasoning.

Data Science & Analytics2 min read

Convert string timestamps to datetime and extract day of week

This tests pandas datetime parsing and accessor fluency. A strong answer uses pd.to_datetime, assigns the result, then extracts the day via .dt.day_name() or .dt.dayofweek. Red flag: manual string splitting or Python loops instead of vectorized ops.

Data Science & Analytics2 min read

What is vectorization in NumPy and pandas?

Tests if you know why NumPy operations beat Python loops via contiguous memory and C-level SIMD. A strong answer defines vectorization as array-wide operations without explicit loops, contrasts a ufunc to a for-loop, and cites interpreter overhead removal.

Describe dbt's role and how it differs from traditional ETL
Analytics & Metrics2 min read

Describe dbt's role and how it differs from traditional ETL

Position dbt as ELT's T with lineage, tests, docs; contrast with Python ETL using external compute and Airflow only scheduling tasks.

asyncio Event Loop Policies: A Deprecated Pattern
Python & FastAPI2 min read

asyncio Event Loop Policies: A Deprecated Pattern

Think of an event loop policy as the global factory for asyncio's event loops, controlling which loop is created and how it's retrieved. It was used to swap implementations, but the entire API is deprecated in Python 3.14 and will be removed in 3.16.

Pydantic BaseSettings: Typed, Layered Configuration
Python & FastAPI2 min read

Pydantic BaseSettings: Typed, Layered Configuration

Pydantic's BaseSettings treats configuration as typed data, not just strings. It automatically loads and validates settings from environment variables, .env files, and secrets stores into a Python object.

Python & FastAPI2 min read

FastAPI: Handling Form Data, Not Just JSON

FastAPI can handle classic HTML form data, not just JSON. Use Form to define expected fields in your endpoint, just like query parameters. It's ideal for login pages. The footgun: forgetting to pip install python-multipart will break form parsing.

FastAPI: Automatic Interactive API Docs
Python & FastAPI2 min read

FastAPI: Automatic Interactive API Docs

FastAPI turns your Python type hints into live, interactive API documentation. It generates an OpenAPI schema to power a UI where you can test endpoints directly from your browser, no extra work needed.

FastAPI: Pydantic for Robust Request Bodies
Python & FastAPI2 min read

FastAPI: Pydantic for Robust Request Bodies

A Pydantic model is a contract for your API's request body. It tells FastAPI what data to expect, automatically converting incoming JSON into a typed Python object. Use this for any POST or PUT endpoint. The footgun is declaring path params in the body model.

MLOps & Infrastructure2 min read

Conda Environments: Isolate Your Project Dependencies

Think of a Conda environment as a separate workshop for each project, with its own tools (packages) and Python version. This prevents dependency conflicts when Project A needs a different library version than Project B.

MLOps & Infrastructure2 min read

PMML: The 'Save File' for Machine Learning Models

PMML is like a universal "save file" for ML models, using XML to describe everything needed for prediction: features, preprocessing, and model structure. It enables training in Python and deploying in Java. The footgun: verbose files and partial tool support.

LLMs & Generative AI2 min read

Self-Querying Retriever: Let an LLM Write Its Own Filters

A self-querying retriever uses an LLM to turn a natural language question into a structured query with metadata filters. It lets users ask things like "Find documents about Python from before 2020," which a simple vector search can't do.

Dask: Parallel Computing with Familiar APIs
Data Science & Analytics2 min read

Dask: Parallel Computing with Familiar APIs

Dask parallelizes Python analytics by breaking data into chunks and building a task graph of operations. It's like giving Pandas and NumPy superpowers for data too big for RAM. The footgun: its lazy evaluation means you must explicitly call .compute().