Search
Find a bite, explore a topic or look for a role.
Results for “Python”
Bites 291

The Python GIL: One Thread at a Time
The Python Global Interpreter Lock (GIL) is a mutex ensuring only one thread executes Python bytecode at a time. This serializes CPU-bound threads, but the lock is released during I/O, making it effective for network-bound tasks.

Python Concurrency vs. Parallelism
Concurrency is juggling tasks; parallelism is doing them at once. In Python, use concurrency (threading/asyncio) for I/O-bound work like API calls, and parallelism (multiprocessing) for CPU-bound tasks.

Accessing Python Type Annotations Safely
Accessing an object's type hints isn't just obj.__annotations__. Use inspect.get_annotations() in Python 3.10+ for safe access. This is key for tools like FastAPI that introspect your code.

Python's async/await: Concurrent, Not Parallel
async/await lets a single Python thread juggle multiple tasks, pausing one to work on another while it waits for I/O. It's ideal for network requests or database queries. The footgun: it won't speed up CPU-bound tasks, it only helps with waiting.

Python Coroutines: Functions You Can Pause and Resume
A Python coroutine is a function that can be paused and resumed. It yields control during I/O waits, allowing other tasks to run instead of blocking the program. The main footgun: calling an async function does nothing; you must await it to run it.

The `with` Statement: Python's Automatic Cleanup Crew
A context manager is Python's automatic cleanup crew. It uses the with statement to guarantee setup and teardown code runs, even if errors occur. It's essential for files and database connections.

Python's `yield`: Functions That Pause and Resume
Python's yield creates a generator: a pausable function that produces values on-demand, saving memory. Use it for large files or infinite sequences. The footgun: a generator is a one-time-use iterator; you can't loop over it twice.

Python Decorators: Functions that Wrap Functions
A decorator is a function that wraps another function, adding behavior without modifying the original code. They're used for caching, logging, or access control. The main footgun is forgetting that decorators run at definition time, not call time.

Python Enums: Give Names to Magic Numbers
Python's Enum gives meaningful names to "magic numbers" or strings. Use it for fixed sets of options like statuses or categories to make code self-documenting. The footgun: don't compare members to raw values; compare member to member for type safety.

Python Packages: Grouping Modules with __init__.py
A Python package is a folder of modules treated as one unit. The __init__.py file marks the folder as a package and can run setup code. Use it to organize large codebases.

Python Data Classes: Write Less Boilerplate
Python's @dataclass decorator writes boilerplate code like __init__ and __repr__ for you, turning a class with type hints into a data container. Use it for API payloads or simple records.

Python Type Hints: Documentation Your Linter Can Read
Type hints describe expected values, but Python itself does not enforce them while running. Static checkers and IDEs use the annotations before execution; libraries such as FastAPI can also inspect them for validation and API documentation.

Python Virtual Environments: Isolate Project Dependencies
A Python virtual environment is a self-contained directory with its own Python interpreter and packages, preventing dependency conflicts between projects. The biggest mistake is checking the environment folder into source control; it's disposable and meant to…

Cython: Static Typing for Faster Python
Cython speeds up Python by compiling it to C, especially when you add static types to bypass Python's dynamic overhead. Use it for CPU-bound bottlenecks like tight loops in numerical code.

R & Python Interoperability with Reticulate
Reticulate embeds a Python session inside R, letting you use Python libraries as if they were native R objects. Use it when a team uses both languages or you need a Python library in an R workflow.
pandas .apply() versus vectorized operations
Apply runs a Python function per row or column, flexible but slow due to per-element looping; prefer vectorized ops; use apply only for custom logic with no vectorized equivalent.
Vercel Ship 2026: agent stack, eve framework, and microservices
Vercel Ship 2026 unveils open-source eve framework and Vercel Services for microservices July 1. Vercel is repositioning as agentic infrastructure with Connect credentials and expanded Python backends. Evaluate if your next agent deploys here instead of AWS.

What are the key responsibilities for Nginx versus Uvicorn?
This tests the reverse-proxy versus ASGI-server boundary. A strong answer gives Nginx TLS termination, static files, buffering, and load balancing, while Uvicorn runs the Python app and async workers.

Walk me through a basic Dockerfile for a FastAPI app
Slim base, install deps before app code to cache layers, expose port, exec-form CMD for Uvicorn.
Implement a FastAPI file upload endpoint with form data
Tests FastAPI multipart literacy. A strong answer names python-multipart, uses Annotated[UploadFile, File()] for the image, and Annotated[str, Form()] for user_id.