Skip to content
tezvyn:

Search

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

Results for Python

Bites 291

Data Science & Analytics2 min read

Python Virtual Environments

A virtual environment is an isolated Python installation with its own packages, so each project gets the exact dependency versions it needs without conflicting with other projects or the system Python.

Python & FastAPI2 min read

Explain multi-stage Docker builds for Python and builder vs runtime

Tests separation of build-time and runtime concerns. A strong answer contrasts the builder stage (gcc, headers, wheels) with the runtime stage (slim base, copied artifacts, no compiler). Red flag: citing size alone while ignoring security and caching.

Why are contextvars better than threading.local in async Python?
Python & FastAPI2 min read

Why are contextvars better than threading.local in async Python?

This tests whether you know async tasks share OS threads, making thread-local storage unsafe for request state. A great answer notes ContextVar is task-local and resets automatically, while threading.local bleeds across concurrent coroutines.

How do you use a Python class as a FastAPI dependency?
Python & FastAPI2 min read

How do you use a Python class as a FastAPI dependency?

It tests whether you understand FastAPI DI beyond functions and when stateful encapsulation wins. Explain that Depends takes callable classes, centralizing setup and shared state in __init__. Red flag: claiming classes are pure syntactic sugar.

What is the difference between def and async def in Python and FastAPI?
Python & FastAPI2 min read

What is the difference between def and async def in Python and FastAPI?

Tests event-loop boundaries: async def yields control via await for non-blocking I/O, def runs in a threadpool. Use async def only with async libraries; def covers blocking calls. Red flag: claiming async is automatically faster or awaiting inside def.

Explain Python type hints and their importance in FastAPI
Python & FastAPI2 min read

Explain Python type hints and their importance in FastAPI

Python type hints describe expected data, but Python itself does not enforce them. FastAPI reads those annotations with Pydantic to parse and validate requests and generate OpenAPI documentation. A strong answer separates language syntax from framework behavior.

Python Async Context Managers
Python & FastAPI2 min read

Python Async Context Managers

Async context managers let you await during setup and teardown. Use async with for database connections or streams where acquiring and releasing both need I/O. The footgun is applying @contextmanager to async cleanup, which cannot await and will crash.

MLOps & Infrastructure2 min read

Why avoid global Python dependencies for ML, and how do containers help?

This probes environment isolation and reproducibility in ML. A strong answer cites global dependency conflicts, system library skew, and brittle environments; then notes containers freeze the full stack for deterministic deployment.

MLOps & Infrastructure2 min read

How do you containerize a Python training script for GPU cloud VMs?

This tests reproducible GPU containerization. A strong answer uses an NVIDIA CUDA base image, installs Python dependencies at build time, copies the training script, and runs with --gpus.

MLOps & Infrastructure2 min read

Walk me through essential Dockerfile commands for a reproducible Python ML environment

Tests your ability to containerize Python ML scripts reproducibly. A strong answer covers FROM with a pinned slim image, WORKDIR, COPY for requirements and code, RUN pip install, and CMD or ENTRYPOINT.

Data Science & Analytics2 min read

Vectorization: Ditch the Python Loop

Vectorization means issuing one batch command to C-backed arrays instead of looping in Python. Use it for million-row DataFrames or matrix math. The footgun is treating apply() as vectorized, or silently materializing giant temporaries that exhaust RAM.

Mangum: Run Python ASGI Apps on Serverless
Python & FastAPI2 min read

Mangum: Run Python ASGI Apps on Serverless

Mangum is an adapter for running Python ASGI apps (like FastAPI) on serverless platforms like AWS Lambda. It translates serverless events into ASGI requests, letting you deploy existing async web apps without a rewrite.

Python & FastAPI2 min read

Your First Python Dockerfile Blueprint

A Dockerfile is a recipe for building a self-contained environment for your Python app. Use it to ensure your app runs identically everywhere, from your laptop to production. The common footgun is forgetting a .dockerignore file, which bloats your image.

Password Hashing with Python's Passlib
Python & FastAPI2 min read

Password Hashing with Python's Passlib

Passlib turns plaintext passwords into secure, salted hashes that are safe to store. Use it in any Python app with user accounts to handle logins. The footgun: never compare hashes directly; always use the .verify() method to prevent timing attacks.

Python & FastAPI2 min read

Beanie: Python Objects as MongoDB Documents

Beanie maps Pydantic models to MongoDB documents, letting you interact with the database using Python objects instead of raw queries. Use it in async apps like FastAPI for rapid, type-safe CRUD.

Motor: Don't Block Your Python App on MongoDB
Python & FastAPI2 min read

Motor: Don't Block Your Python App on MongoDB

Motor is the async bridge for Python apps to talk to MongoDB without blocking. Use it in FastAPI or other async frameworks to keep your server responsive during database queries.

Python & FastAPI2 min read

SQLAlchemy Declarative: Python Classes as Database Tables

SQLAlchemy's Declarative Mapping lets you define database tables as Python classes. You write a class with typed attributes, and SQLAlchemy generates the SQL. It's the standard way to use the ORM, turning database rows into Python objects.

Debugging Python's Asyncio
Python & FastAPI2 min read

Debugging Python's Asyncio

Debugging asyncio is about finding what's blocking the single-threaded event loop. Use its debug mode to detect slow callbacks and run_in_executor to offload CPU-bound work. The biggest mistake is calling blocking code directly, which stalls the entire app.

Python's Asyncio Subprocesses: Non-Blocking Shell Commands
Python & FastAPI2 min read

Python's Asyncio Subprocesses: Non-Blocking Shell Commands

Run external commands without blocking your async app's event loop. asyncio.create_subprocess_shell lets you launch processes and await their results, keeping your server responsive.

Pydantic's Data Coercion: From Raw Data to Python Types
Python & FastAPI2 min read

Pydantic's Data Coercion: From Raw Data to Python Types

Pydantic automatically converts raw data, like strings from a JSON request, into the Python types you declare. It's how FastAPI turns a JSON body into a typed Python object.