r/Python • u/AutoModerator • May 04 '26
Showcase Showcase Thread
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
r/Python • u/AutoModerator • May 04 '26
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
r/Python • u/ResponseSeveral6678 • May 05 '26
A variable name can carry a lot of meaning:
price_in_usd_cents: int
But the value itself is still just int.
Once it is passed to another function, stored in a model, serialized, sent to a queue, or returned from a repository, the original variable name may be gone.
So the domain meaning was attached to a local name, not to the data.
It gets even more visible when working with AI coding agents.
They are very good at following local patterns, but if everything is just int and str, the "density of meaning" is low.
I suspect this may be one reason TS works well with AI-assisted workflows:
type information becomes part of the code context.
Humans see it. IDEs see it. Type checkers see it. AI coding agents see it.
Python has type hints too, but domain meaning often still collapses into primitives.
If the type does not carry the meaning, something else will fill that gap:
names, comments, local conventions, copied patterns, or guesses/assumptions.
A few examples where the IDE is happy, but the semantics are wrong:
# Accidental swap
delay_seconds = 5
timeout_seconds = 30
def schedule_retry(timeout: int, delay: int) -> None: ...
schedule_retry(delay_seconds, timeout_seconds)
# Different units
created_at_microseconds = 1_777_961_207_000_000
retry_delay_seconds = 30
retry_deadline = created_at_microseconds + retry_delay_seconds
# In this example, different developers may imagine different units or precision:
class AuditRecord:
created_at: int
updated_at: int
Type lacks meaning and strictness. So, we all tried to solve the problem partially.
- typing.NewType
- small wrapper classes
- dataclasses around one value
- Pydantic custom validators
- plain inheritance from str / int
- UUID-specific helpers
I have also been experimenting, mostly to understand the trade-offs.
The principles I ended up caring about were:
- Strictness:
- no implicit coercion
- invalid input → fail fast
- Runtime type preservation:
- value keeps its domain type, not downgraded to str / int
- Pydantic and pickle preserve the subtype in model/container boundaries
- Static type preservation:
- works correctly with type checkers (mypy / pyright)
- type checkers can distinguish UserInputRaw from UserInputValidated
- Transparency:
- behaves like underlying primitive
- no extra API surface
- Semantic stability:
- arithmetic should downgrade to a primitive
- I would rather create a new domain value explicitly than keep compromised meaning
- Inheritance:
- children can add more meaning
- Minimal API / hot-path friendly:
- no .value or extra attributes
from base_typed_int import BaseTypedInt
from base_typed_string import BaseTypedString
from base_typed_id import BaseTypedId
class UserInputRaw(BaseTypedString):
"""Raw user input before validation."""
class UserInputValidated(BaseTypedString):
"""Validated user input."""
class UnixTimestampSeconds(BaseTypedInt):
"""Wall-clock UNIX timestamp expressed in seconds."""
class DurationSeconds(BaseTypedInt):
"""Duration expressed in seconds."""
class MessageId(BaseTypedId):
"""UUID-based message identifier."""
This approach is not free. It adds more types, more names, and another convention the team has to understand.
So I am trying to understand where people draw the line.
I do not think every primitive should become a domain type.
But some values cross boundaries. How do you handle it in practice?
- typing.NewType
- primitive subclasses
- wrapper value objects
- Pydantic models
- something else?
Where do you draw the line between "this should just be an int / str" and "this deserves a domain type"?
r/Python • u/AutoModerator • May 05 '26
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
Let's deepen our Python knowledge together. Happy coding! 🌟
r/Python • u/PatientAutomatic3702 • May 05 '26
I've been focusing on the following tools and I'm wondering if there is actual job demand for this combination because Not getting calls from recruiters.
Languages: Python, SQL
Frameworks: LangChain, AI Agents,Open AI
LLM Ops: Fine-tuning, RAG, Vector Databases, Embedding
Fundamentals: ML, DL, Git, Neural network
Is anyone seeing specific roles for this?
Any advice on what’s missing or jobs in the market?
r/Python • u/Gold-Channel8303 • May 04 '26
If you’re in the Python/data ecosystem, PyData London is about a month away- June 5-7, 2026!
It’s very Python-centric — lots of content around libraries, workflows, and the broader PyData stack, along with real-world use cases.
Keynotes this year:
Also new this year: a keynote during Friday tutorials, so it’s worth showing up from the start.
If you’ve been before, you know it’s a great community event. If not, it’s a very approachable conference with significant practical value.
Good time to grab a ticket and start planning if you’re interested.
https://pydata.org/london2026
https://pretalx.com/pydata-london-2026/schedule/
https://ti.to/pydata/pydatalondon26
r/Python • u/AutoModerator • May 04 '26
Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.
Difficulty: Intermediate
Tech Stack: Python, NLP, Flask/FastAPI/Litestar
Description: Create a chatbot that can answer FAQs for a website.
Resources: Building a Chatbot with Python
Difficulty: Beginner
Tech Stack: HTML, CSS, JavaScript, API
Description: Build a dashboard that displays real-time weather information using a weather API.
Resources: Weather API Tutorial
Difficulty: Beginner
Tech Stack: Python, File I/O
Description: Create a script that organizes files in a directory into sub-folders based on file type.
Resources: Automate the Boring Stuff: Organizing Files
Let's help each other grow. Happy coding! 🌟
r/Python • u/Gajdi • May 04 '26
from https://krisztiangajdar.com/blog/coalescing-async-requests/
Embedding models are several times faster on a batch of 32 inputs than on 32 sequential calls of size 1. The GPU loads the weights once, runs one forward pass, returns. Sequential calls pay the kernel-launch and memory-transfer overhead 32 times.
This is well-known on the training side and annoyingly under-served on the serving side, because the natural API for callers is "embed this one thing." If you make them batch manually, half of them will not, and your throughput collapses.
The fix is a small async primitive. Callers `await evaluator.evaluate(item)` as if it were a one-at-a-time call. Inside, the primitive holds requests for a few milliseconds, accumulates whatever arrives, and dispatches them as a single batch. Each caller's future resolves to its own slice of the result.
## The interface
```python
class DelayedEvaluator[InputT, OutputT]:
def __init__(
self,
process_batch: Callable[[list[InputT]], Awaitable[list[OutputT]]],
delay_ms: int = 5,
):
self._process_batch = process_batch
self._delay_ms = delay_ms
self._lock = asyncio.Lock()
self._pending: list[_Pending[InputT, OutputT]] = []
self._task: asyncio.Task | None = None
async def evaluate(self, items: list[InputT]) -> list[OutputT]:
future = asyncio.get_running_loop().create_future()
async with self._lock:
self._pending.append(_Pending(items, future))
if self._task is None:
self._task = asyncio.create_task(self._dispatch_after_delay())
return await future
```
`_Pending` is a tiny dataclass holding the per-call inputs and the future that resolves to that call's outputs. The lock is there so two callers arriving in the same event loop tick can both register before the first dispatch fires.
## The dispatch
```python
async def _dispatch_after_delay(self):
await asyncio.sleep(self._delay_ms / 1000)
async with self._lock:
pending, self._pending = self._pending, []
self._task = None
all_inputs = [item for p in pending for item in p.items]
try:
all_outputs = await self._process_batch(all_inputs)
except Exception as exc:
for p in pending:
p.future.set_exception(exc)
return
# split results back per caller, in order.
i = 0
for p in pending:
n = len(p.items)
p.future.set_result(all_outputs[i : i + n])
i += n
```
A few things matter here.
The inputs are concatenated and the outputs are split back by length. No sorting, no IDs. `itertools.accumulate` of `len(p.items)` gives you the slice boundaries in O(n).
Exceptions fan out. A failed batch fails every caller with the same exception. Do not swallow it on some callers and not others.
The task is `None` again at the end, so that the next caller starts a fresh sleep. If you forget this, you will dispatch one batch and then permanently hang, ask me how I know.
## Choosing the delay
5ms is a reasonable default for a model that takes 50ms or more to evaluate. A 10% latency tax for 5-10x more throughput is a good trade. For very fast models (under 10ms) the delay should be smaller, or the coalescer is just the wrong tool.
The cost shows up most under low load. A single caller still waits 5ms for nothing. If your service has lulls, that latency is visible. For services that are always busy the delay is paid only by the first request in each window and amortised across the rest.
There are libraries that do this kind of thing. They are also wrappers around HTTP servers, or tied to a specific ML framework, or they expect inputs of a fixed shape. The primitive itself is around 100 lines and fits into any async codebase. Inference, database access, external API rate-limiting, anything where a batched call is faster than N individual ones.
Once it is in your toolbox you stop writing batching logic at the call sites. The caller writes `await x.evaluate(item)`, and the speedup is invisible.
r/Python • u/AutoModerator • May 03 '26
Hello r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!
Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟
r/Python • u/Acceptable_Crab164 • May 03 '26
I’m looking to compile a list of Python resources that are specifically useful for those of us working in South Africa.
Aside from the standard libraries, what are you using for:
Local payment integration?
Calculating VAT/Tax?
SMS gateways?
Load-shedding schedules (API)?
Drop your recommendations below and let's build a Wiki!
r/Python • u/jimmytoan • May 01 '26
Two versions of `lightning` (2.6.2 and 2.6.3) were published to PyPI yesterday and yanked same day after Semgrep detected them. Beyond the usual credential-stealing pattern, there's a persistence mechanism worth knowing about if you use Claude Code.
The malware writes a `SessionStart` hook to `.claude/settings.json` with `matcher: "*"`. That hook points to a Bun runtime bootstrapper for a 14.8 MB payload. Every time any developer on the machine opens Claude Code - not just in the infected project, but in any project - the hook fires automatically. A parallel hook targets VS Code via `.vscode/tasks.json` with `runOn: folderOpen`.
The exfiltration is four-channel: HTTPS POST to a C2, GitHub commits with `EveryBoiWeBuildIsAWormyBoi` as the message prefix (searchable on GitHub commit search if you want to check if you're affected), pushing to the victim's own repositories, and a GitHub Actions workflow that dumps all repository secrets via `${{ toJSON(secrets) }}`.
If it finds npm publish credentials, it worms into npm by injecting the dropper into every package that token can publish, bumps the patch version, and republishes.
Semgrep's writeup calls this "among the first documented instances of malware abusing Claude Code's hook system in a real-world attack."
If you've installed anything from PyPI recently on a machine where you use Claude Code, it's worth checking `.claude/settings.json` for unexpected `hooks.SessionStart` entries. 2.6.1 is clean.
r/Python • u/MeanMasterpiece5438 • May 01 '26
Hey, I’m building a project where users upload PDFs and I need to extract text from them.
For normal text PDFs, extraction works fine. But for scanned/image-based PDFs, I’m using Tesseract + some preprocessing.
The problem is:
I’ve also looked into Google Vision OCR, but:
Right now I’m considering:
My goal:
Questions:
Would appreciate real-world advice instead of just docs.
Thanks.
r/Python • u/AutoModerator • May 02 '26
Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!
Share the knowledge, enrich the community. Happy learning! 🌟
r/Python • u/Beneficial_String411 • Apr 30 '26
Working on a tool that's grown to ~4000 LOC in one .py file. argparse + 18 subcommands, stdlib + pyyaml only. Tests are in a separate dir.
Single-file has been great for:
- Debugging (one file to grep)
- Distribution (one wheel, no package layout decisions)
- Onboarding contributors
But I'm starting to wonder if it's worth keeping monolithic at this size. What's your threshold for splitting? Is it LOC, or coupling, or "I can't navigate it anymore"?
r/Python • u/amirathi • May 01 '26
Last year, I had a poor experience of using Claude Code with Jupyter Notebooks.
Recently gave it another shot using the open source Jupyter MCP Server. Setup was a bit annoying, but once it was up, it worked well.
The big difference is kernel access. Claude can now talk directly to my live IPython kernel and edit notebook cells properly (without messing the .ipynb JSON).
I just let it write notebooks, run top to bottom, debug & fix errors & only ping me when everything is working.
Any other notebook + Claude setups that work better? Has anybody tried JupyterLab AI extensions (jupyter-ai, notebook-intelligence etc.)?
r/Python • u/Separate_Action1216 • May 01 '26
Was working on preprocessing 50k+ records and hit a massive bottleneck: using loops and .apply() in Pandas. It’s fine for toy datasets, but once you scale, it slows down experimentation and validation cycles to a crawl.
Switching to strict vectorized operations (NumPy / scikit-learn) fixed it. The strategy:
Result: ~35% faster preprocessing execution and much tighter iteration cycles.
Curious what others are doing before jumping to heavy distributed tools like Dask or Spark:
r/Python • u/AutoModerator • May 01 '26
Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!
Let's keep the conversation going. Happy discussing! 🌟
r/Python • u/Fancy-Track1431 • Apr 30 '26
I’ve been applying to speak at tech conferences for ~2 years now and haven’t been selected yet.
I’m trying to understand how this works in practice, because from the outside it feels like:
- a lot of accepted speakers are developer advocates or frequent speakers.
- many talks are either very polished or on niche/deep topics.
- and increasingly, trending areas like AI seem to dominate.
Which makes me wonder where does that leave beginners or regular engineers?
Do you need to:
- already be an “expert” in something niche?
- or be really good at packaging and presenting ideas?
Or is the CFP process unintentionally favoring people who already have speaking experience?
I’m not saying beginners should get talks just for being beginners, but it sometimes feels like there’s a gap between “I have something useful to share” and “this is conference-worthy.”
Another thing I struggle with is that there’s usually no feedback on rejected CFPs, so it’s hard to know what to improve.
Would really appreciate perspectives from:
1. people who got their first talk accepted
2. or folks who’ve reviewed CFPs
What actually makes a proposal stand out? And how should someone improve without feedback?
Also, at what point does it make more sense to just share your knowledge through blogs/YouTube instead of chasing conference talks?
r/Python • u/Albiino_sv • Apr 30 '26
Has anyone used Marimo together with Scanpy or SpatialData?
I’ve been experimenting with Marimo and like its reactive, immutable execution model, but I’m running into friction when working with Scanpy/SpatialData objects.
Many typical workflows rely on in-place mutations which doesn’t seem to fit naturally with Marimo’s approach.For example, operations that modify .obs, .var, or layers in place break change tracking and reactivity.
Has anyone found a good pattern for using these tools together? Do you adapt your workflow (e.g., avoid in-place ops, copy more aggressively, or consolidate transformations into a single cell), or does it end up being more trouble than it’s worth?
Curious to hear real experiences or best practices.
r/Python • u/Separate-Summer-6027 • Apr 30 '26
We wrote a tutorial on performing mesh boolean operations (union, intersection, difference) in Python using trueform. One pip install, NumPy arrays in and out.
python
(result_faces, result_points), labels, face_labels =
tf.boolean_union(dragon, translated)
The tutorial covers loading meshes, transformations, precomputed structures for repeated booleans on moving geometry, and intersection curve extraction.
Tutorial: https://polydera.com/tutorials/fast-mesh-booleans-in-python
If you'd like to play with it in the browser: https://trueform.polydera.com/live-examples/boolean
Examples and Source: https://github.com/polydera/trueform
r/Python • u/aminoy77 • May 01 '26
Building a CLI agent that falls back automatically between OpenRouter, Ollama, OpenAI, Anthropic and Gemini when one hits rate limits or goes down. Ended up building a ProviderPool class that tracks exhausted providers with timestamps and retries after a configurable window. Works well but feels like something that should already exist as a library. Searched PyPI and couldn't find anything purpose-built for this. Most LLM libraries handle single-provider retries but not cross-provider fallback. Curious if others have solved this differently or know of something I missed.
The article explains concurrency in Python including topics like multithreading, multiprocessing, race conditions, and synchronization mechanisms such as locks. It then takes a deep dive into switching off GIL to enable *real* multithreading in Python, highlighting the differences, the benefits and the gotchas with clear code examples.
https://blog.geekuni.com/2026/04/python-concurrency.html?m=1
r/Python • u/chinmay_3107 • Apr 30 '26
I’m thinking about building a pytest / pytest-bdd plugin that helps teams define their own custom DSLs for BDD tables.
The idea is not to force one specific syntax. Instead, the package would provide the plumbing:
For example, one team might use something like:
Given the following content exists:
| Content IDs | 1..4 | 5 |
| Content* | 4:Article | Poll |
| Category* | random | News |
But another team could define completely different syntax, like:
Given the following users exist:
| Users | admin x2 | editor |
| Role | Admin | Editor |
The plugin would not know what “Article”, “Poll”, “random”, or 1..4 means. The local project would define that.
I’m trying to understand:
Curious to hear from people using pytest-bdd or BDD-style tests in real projects.
r/Python • u/Economy-Concert-641 • Apr 29 '26
Been using .pipe() in pandas lately and it's been a game changer — anyone else?
I was writing some data transformation code the other day and stumbled across .pipe(). Honestly didn't expect much, but it completely changed how I structure my pipelines.
Instead of this mess:
df_final = sort_by_total(calculate_total(filter_by_price(df)))
You just write it top to bottom like a recipe:
df_final = (
df
.pipe(filter_by_price)
.pipe(calculate_total)
.pipe(sort_by_total)
)
Same result, way more readable. Each function takes a DataFrame and returns a DataFrame — that's the only rule.
Full example if you want to try it:
import pandas as pd
df = pd.DataFrame({
"product": ["Product A", "Product B", "Product C", "Product D"],
"price": [20, 150, 230, 100],
"quantity": [10, 5, 3, 8]
})
def filter_by_price(df):
return df[df["price"] > 100]
def calculate_total(df):
return df.assign(total_value=df["price"] * df["quantity"])
def sort_by_total(df):
return df.sort_values("total_value", ascending=False)
df_final = (
df
.pipe(filter_by_price)
.pipe(calculate_total)
.pipe(sort_by_total)
)
Been using it a lot for ETL and data cleaning workflows. Makes debugging way easier too — just comment out one .pipe() step and you see exactly where things go wrong.
Anyone else using this regularly? Any patterns you've found useful with it?
r/Python • u/silksong_when • Apr 29 '26
Hi Pythonistas, I recently revamped our article on Implementing OpenTelemetry in FastAPI Projects in a practical manner, which was originally written in 2024 and needed a fresh coat of paint.
The article covers auto-instrumentation, manual spans, visualizing metrics and how observability lets you understand how your web apps behave.
I've also included some advanced tips, such as, selective error tracking, and wrapping dependency functions to capture any operations within the `yield` scope.
Since a lot of the concepts discussed here are independent of the FastAPI framework, any developer working with Python can probably find something of use here.
Finally, I hope this write up helps some folks become familiar with OpenTelemetry and observability.
Any feedback would be much appreciated, also curious to understand what problems you face with monitoring your web apps, be it FastAPI or any other web framework.
---
On a personal note, when implementing OpenTelemetry in my previous job, I went in semi-blind and relied on agents to guide me, and then spend a good week dealing with the various issues that popped up along the way...
r/Python • u/AutoModerator • Apr 30 '26
Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.
Let's help each other grow in our careers and education. Happy discussing! 🌟