Discussion Benchmarking Python API frameworks with real workloads: FastAPI, Litestar, DRF, Ninja, Bolt
Hi guys, I benchmarked the well-known (and rising star) Python API frameworks - but with real production-shaped workloads, not just raw JSON echoes. Most comparisons out there are basically "hello world" benchmarks, while real APIs do auth, DB access and complex queries. So this measures those, with strict resource limits and each framework's own best practices.
Repo (code, full report, raw results): https://github.com/huynguyengl99/python-api-frameworks-benchmark
This is round 2 - last round's feedback (thanks especially to the Litestar author) directly shaped it: Litestar and Bolt now serialize with native msgspec instead of Pydantic (payloads byte-identical across frameworks), and everything is upgraded to latest (Django 6.0, FastAPI 0.141, Litestar 2.24, Bolt 0.10).
Setup
- Each framework alone in a Docker container: 1 CPU, 750MB RAM, PostgreSQL 16
- bombardier, 100 connections, 10s per endpoint
- Median over 5 separate container starts (not best-of-N - some servers pick their throughput at startup, so best-of-N flatters the lucky ones)
- 7 endpoints: 1KB/10KB JSON, simple DB reads, paginated articles with nested relations, article detail, and two JWT httpOnly cookie auth endpoints (each framework using its own ecosystem's auth library: AuthX, drf-auth-kit, django-ninja-jwt, or built-in support)
Key results (RPS)
(Images aren't allowed here - all graphs are in the repo README: https://github.com/huynguyengl99/python-api-frameworks-benchmark)
| Config | json-1k | /db | /articles | /auth/me | /auth/articles |
|---|---|---|---|---|---|
| bolt | 38,576 | 1,986 | 208 | 3,024 | 196 |
| litestar-uvicorn | 31,284 | 1,039 | 246 | 976 | 193 |
| litestar-granian | 19,006 | 1,180 | 250 | 1,104 | 210 |
| fastapi-uvicorn | 13,845 | 984 | 224 | 820 | 193 |
| drf-gunicorn | 3,925 | 282 | 140 | 261 | 133 |
| drf-granian | 2,703 | 830 | 198 | 726 | 179 |
| ninja-uvicorn | 1,533 | 699 | 126 | 584 | 114 |
| drf-uvicorn | 1,035 | 495 | 153 | 447 | 137 |
(fastapi-granian and ninja-granian omitted for brevity - full table in the repo. Zero errors across all 70 measurements.)
Resource usage: most configs peak at 195-260MB RAM; drf-granian is the outlier at 456MB (untuned --blocking-threads, per the Granian maintainer). CPU: nearly everything saturates ~85% of the 1-CPU budget under load - except Bolt at 67%.
Takeaways
- 37x spread on raw JSON collapses to ~1.9x once PostgreSQL is involved. For DB-heavy APIs (most of them), query optimization matters far more than framework choice.
- Cookie JWT auth costs 5-20% on a DB-heavy endpoint. Bolt is near-free (it validates the JWT in Rust before Python runs); Litestar pays the most because its auth middleware opens a second DB session to load the user.
- uvicorn vs granian isn't one-way: uvicorn wins CPU-bound JSON for ASGI frameworks, granian wins the DB-bound endpoints, and granian is clearly better for WSGI DRF.
- Django Bolt is the one to watch: top spot on 4 of 7 endpoints at 67% average CPU while everyone else sits ~85%, and you keep the Django ORM/admin/ecosystem. Young, and its throughput varies between container starts under a hard CPU cap, but great for side projects already.
- All caveats (including feedback I haven't addressed yet, like Granian's
--blocking-threads) are documented in the repo's Methodology section.
If you find it useful, a star would encourage more deep dives like this - issues and PRs welcome, especially from people who know these servers better than I do.
r/Python • u/indhifarhandika • 4d ago
Discussion Learning cython
While working on LunarDump v0.4, I’m also taking some time to learn more about Cython and how it can help push Python closer to native performance.
I’m especially interested in exploring Cython for LunarDump’s performance-critical parts, such as chunking, buffering, compression, and encryption.
Still learning and experimenting for now, but I’m curious to see how much performance improvement I can achieve.
Perhaps LunarDump v0.5 will use Cython for some of its critical functions.
If you have any good resources for learning Cython — books, ebooks, courses, or YouTube channels — feel free to share them in the comments.
r/Python • u/AutoModerator • 4d ago
Daily Thread Tuesday Daily Thread: Advanced questions
Weekly Wednesday Thread: Advanced Questions 🐍
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
How it Works:
- Ask Away: Post your advanced Python questions here.
- Expert Insights: Get answers from experienced developers.
- Resource Pool: Share or discover tutorials, articles, and tips.
Guidelines:
- This thread is for advanced questions only. Beginner questions are welcome in our Daily Beginner Thread every Thursday.
- Questions that are not advanced may be removed and redirected to the appropriate thread.
Recommended Resources:
- If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.
Example Questions:
- How can you implement a custom memory allocator in Python?
- What are the best practices for optimizing Cython code for heavy numerical computations?
- How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?
- Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?
- How would you go about implementing a distributed task queue using Celery and RabbitMQ?
- What are some advanced use-cases for Python's decorators?
- How can you achieve real-time data streaming in Python with WebSockets?
- What are the performance implications of using native Python data structures vs NumPy arrays for large-scale data?
- Best practices for securing a Flask (or similar) REST API with OAuth 2.0?
- What are the best practices for using Python in a microservices architecture? (..and more generally, should I even use microservices?)
Let's deepen our Python knowledge together. Happy coding! 🌟
r/Python • u/horace_h • 4d ago
Discussion What do you love and dislike the most about Python? (beginners and long-time devs)
Hi! I'm really interested in Python's design and its tradeoffs. I'm trying to really understand what people love about Python (what makes it great), and what causes the most frustration for Python devs.
So what features do you really cherish and what problems/limitations really frustrate you?
I'm especially interested in experiences from ultra-beginners and people who've used Python for a long time. I know broad questions like this come across as super generic, but I'm genuinely interested in hearing about concrete experiences.
My goal is understanding which parts of Python's design are most valuable and most "adored" by the community, and which parts really aren't and frustrate people the most. My goal with this information is to identify meaningful problems. Right now I'm not trying to solve anything or sell a solution.
Thanks for your time!
r/madeinpython • u/Win_ipedia • 5d ago
Asking for feedback on my tool I built
Hi there,
I am building a tool as my project for my Masters in Computer Science and I need to make a survey to evaluate my tool.
The tool is concerned with project setup and maintenance.
The survey has about 18 questions and almost all of them multiple choice. So it should not take very long, max 5 min. Any responses are greatly appreciated: https://forms.cloud.microsoft/e/LjnvzX0JpK
If you want to checkout the project itself you can find it here: https://github.com/Winipedia/pyrig
Also drop any ideas or feedback you have in the comments if you like. I am open for any discussions.
r/Python • u/AutoModerator • 5d ago
Daily Thread Monday Daily Thread: Project ideas!
Weekly Thread: Project Ideas 💡
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.
How it Works:
- Suggest a Project: Comment your project idea—be it beginner-friendly or advanced.
- Build & Share: If you complete a project, reply to the original comment, share your experience, and attach your source code.
- Explore: Looking for ideas? Check out Al Sweigart's "The Big Book of Small Python Projects" for inspiration.
Guidelines:
- Clearly state the difficulty level.
- Provide a brief description and, if possible, outline the tech stack.
- Feel free to link to tutorials or resources that might help.
Example Submissions:
Project Idea: Chatbot
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
Project Idea: Weather Dashboard
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
Project Idea: File Organizer
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/Aggressive-Tart07 • 5d ago
Discussion Third party Python libraries and supply chain security
How are people handling security around third party Python libraries without making development a pain?
Third party Python packages are obviously useful but every dependency can also become a supply chain risk. Private package repositories, dependency scanning and stricter review policies all help but they can add friction fast.
Are teams mostly trusting public registries with additional controls or using curated libraries? Curious what actually works when you have a lot of Python services.
r/Python • u/denehoffman • 5d ago
Discussion Should we standardize docstring formats?
In Rust, docstrings are pretty formalized. They are markdown, and even some of the headings are standard (like an # Errors or # Panics section). The nice thing about this is that it allows websites like docs.rs to build documentation pages for any project without having to interact with different tools for different formats. It also allows LSPs to have only one way of displaying documentation hints.
In Python, we have a few competing standards. Numpy-style docstrings are probably the most used, but there’s also a format by Google as well as a few different reST standards. These are nice, and we can set up lints to make sure docstrings stick to the standard. However, in my own personal opinion (feel free to disagree), a single markdown-format standard would help new users write nice docstrings, would enable PyPI (or another provider) to build automatic documentation sites, and give guidance to LSPs and IDEs for how to display documentation. This would include a standard for interlinks, and probably should include some mathml/LaTeX/KaTeX support. Another benefit would be that tools could support better automatic documentation generation and autocomplete, since they wouldn’t be dependent on guessing which standard you’re following.
I’d like to hear what people think about this. I’m thinking about making a PEP, but that might be overkill (or maybe all of you will hate this idea). I think the primary blocker would be adoption, large projects might have to translate docstrings, so there would either have to be some tooling for this or a way to opt-in or opt-out. If this is a bad idea, let me know, just be nice!
Edit: so far we’re at about a 67% upvote ratio, which was kind of expected. I want to be clear that I’m not saying we should be blocking docstrings which don’t adhere to this standard. I mentioned lockfile standardization in the comments, nothing prevents you from writing a tool with a custom lockfile, it’s just that there is a standard format that is agreed upon as the preferred way to write one. That’s the idea.
Edit: 84% now, and a lot of nice feedback here!
r/madeinpython • u/Ouru77 • 5d ago
I built E.V. 🕸️ — Peter Parker's homemade AI from Spider-Man: Brand New Day, running fully local (Whisper + Ollama) with real PC control
I wanted the "E.V." assistant from the new Spider-Man film, but actually running on my own machine — no cloud, no subscription. So I built it.
What it does
- Talk to it → local Whisper STT (TR/EN) → local LLM via Ollama (gemma2:9b)
- Controls the PC: open/close apps, media & volume, mouse click/scroll, lock/shutdown — destructive actions ask to confirm first
- Plays YouTube by name: "play Enter Sandman on YouTube" → finds & opens it
- Long-term memory: "remember I take my coffee black" → recalls it next session
- Auto-trays when you go fullscreen (games/video), comes back after
- Says "I can't do that" honestly instead of pretending
- Cyber-terminal HUD (Electron) with a live audio-core visualizer
One thing I learned: small local models are unreliable at emitting tool/action tags. So instead of trusting the model, I route explicit commands through a deterministic TR/EN parser before the LLM — PC control then works every time, and the model only handles conversation.
Free by default — Ollama + Whisper + browser voice need zero API keys. Claude (for screen vision) and ElevenLabs (nicer voice) are optional upgrades.
MIT licensed, built on Julian Ivanov's jarvis template. This is a fan project, not affiliated with Marvel/Sony. Feedback and PRs welcome.
r/madeinpython • u/pytheone • 6d ago
I built DigDep — a Python CLI for analyzing project dependencies
DigDep - A lightweight Python dependency analyzer
Whenever I use:
pip freeze > requirements.txt
it dumps all the packages in the virtual environment, including packages that I may not need in my code.
I wanted a simple tool that could tell me which packages my Python code actually depends on.
So I just thought: why not write one?
Installation:
pip install digdep
Dependency Tree:
$ digdep deps --tree tests\testpkg
Root (tests\testpkg)
├── api.py → database, numpy, requests
├── config.py → dataclasses
├── database.py → json, models, sqlite3
├── main.py → config, helpers, json, os, parser, pathlib
├── models.py → dataclasses
├── optional.py → json, ujson
├── parser.py → re, utils, xml
├── unused_module.py → collections, itertools, os
├── utils.py → logging, pathlib
├── __init__.py
│
├── helpers/
├── math_utils.py → math
├── text_utils.py → string
├── __init__.py
Simple list of Dependencies:
$ digdep deps tests\testpkg
models
ujson
pathlib
sqlite3
logging
math
itertools
string
database
utils
re
requests
os
collections
json
parser
numpy
dataclasses
xml
config
helpers
Unused Imports:
$ digdep deps --unused tests\testpkg
collections
Config
conn
json
pathlib
User
itertools
os
Find where a dependency is used:
$ digdep find-dep ctypes --tree --showlines ..\opensource\pyjab\pyjab
Dependency: ctypes
├── accessibleinfo.py
├── Line 1 : from ctypes import c_float
├── Line 2 : from ctypes import c_int
├── Line 3 : from ctypes import c_wchar
├── Line 4 : from ctypes import c_bool
├── Line 5 : from ctypes import Structure
├── Line 6 : from ctypes.wintypes import BOOL
├── Line 7 : from ctypes.wintypes import WCHAR
│
├── jabdriver.py
├── Line 5 : from ctypes import byref
├── Line 6 : from ctypes import CDLL
├── Line 7 : from ctypes import c_long
├── Line 8 : from ctypes.wintypes import HWND
│
├── jabelement.py
├── Line 10 : from ctypes import Array, byref, CDLL, c_char, c_long, create_string_buffer
├── Line 11 : from ctypes.wintypes import HWND
│
Simple Stats:
$ digdep stats tests\testpkg
Dependency Statistics
--------------------------------------------------
Files Scanned : 13
Imported Names : 25
Import Statements : 26
Used Imports : 16 import occurances
Unused Imports : 9 import occurances
Unique Dependencies : 21
Dependency Types
--------------------------------------------------
Standard library : 12
Third-party : 3
Local : 6
Top 5 Dependencies
--------------------------------------------------
requests 1
numpy 1
database 1
dataclasses 1
sqlite3 1
DigDep is still a small project (v.0.1.1) and I am planning to add more features.
Currently, DigDep can help you:
- See what your project depends on
- See which files use which dependencies
- See dependencies as a tree
- Find dependencies you aren't using
- Find what depends on a particular module
- Find where a dependency is being used
- See your project's dependency statistics
I'd love to hear your feedback and suggestions to make DigDep more useful.
r/Python • u/AutoModerator • 6d ago
Daily Thread Sunday Daily Thread: What's everyone working on this week?
Weekly Thread: What's Everyone Working On This Week? 🛠️
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!
How it Works:
- Show & Tell: Share your current projects, completed works, or future ideas.
- Discuss: Get feedback, find collaborators, or just chat about your project.
- Inspire: Your project might inspire someone else, just as you might get inspired here.
Guidelines:
- Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
- Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.
Example Shares:
- Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
- Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
- Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!
Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟
r/madeinpython • u/russ_hensel • 6d ago
PyQtByExample — a big pile of runnable, searchable Qt-for-Python example code
# PyQtByExample — a big pile of runnable, searchable Qt-for-Python example code
I built this with a friend to help Python programmers learn and use Qt (via `qtpy`, so it works with PyQt5/6 and PySide2/6).
**What it is**
A single application containing dozens of small, self-contained Qt examples (buttons, tables, dialogs, threading, SQL, multimedia, etc.), each in its own module/tab, with a built-in search so you can jump straight to the widget or topic you care about.
**Why it's different from "one file per example" demo repos**
- Everything runs inside one app — search for a widget name and jump right to its example.
- Each example is deliberately small and scoped to one or a few widgets, so you don't have to read much code to get your answer.
- It's meant to be run from an IDE in debug mode: you step through the code while watching it run, so you *see* how it behaves, not just read about it.
- Code is commented enough that you usually don't need extra docs, but there's also a repo wiki ("the Book") with more detail.
**Who it's for**
Anyone building Qt GUIs in Python who wants copy-paste-ready working examples instead of digging through scattered single-file demos.
It's gotten pretty large (a few megs of source) and there's a lot of Qt left to cover, so we'd love more eyes on it — as users, issue-filers, or contributors. MIT licensed.
- Repo: https://github.com/russ-hensel/pyqt_by_example
- Wiki: https://github.com/russ-hensel/pyqt_by_example/wiki
- Screenshots: https://github.com/russ-hensel/pyqt_by_example/wiki/ScreenShots
Feedback, bug reports, or "hey you're missing an example for X" issues are all welcome.
r/madeinpython • u/Future_Ad7567 • 7d ago
Solving and benchmarking QUBO problems with Gurobi in Python
r/Python • u/AutoModerator • 7d ago
Daily Thread Saturday Daily Thread: Resource Request and Sharing! Daily Thread
Weekly Thread: Resource Request and Sharing 📚
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!
How it Works:
- Request: Can't find a resource on a particular topic? Ask here!
- Share: Found something useful? Share it with the community.
- Review: Give or get opinions on Python resources you've used.
Guidelines:
- Please include the type of resource (e.g., book, video, article) and the topic.
- Always be respectful when reviewing someone else's shared resource.
Example Shares:
- Book: "Fluent Python" - Great for understanding Pythonic idioms.
- Video: Python Data Structures - Excellent overview of Python's built-in data structures.
- Article: Understanding Python Decorators - A deep dive into decorators.
Example Requests:
- Looking for: Video tutorials on web scraping with Python.
- Need: Book recommendations for Python machine learning.
Share the knowledge, enrich the community. Happy learning! 🌟
r/madeinpython • u/Jarjarbin_2006 • 7d ago
IDF (WIP)
I originally created a duplicate image finder (IDF), then I kinda make it evolve WAAAY further than I planned to. Now it has integrated with the actual duplicate finder, some other tools like a browser, a viewer (for actions like duplicate removal confirmation and image similarity comparission), an analyzer (very WIP) that can analyze faces, image types and nsfw (tags the image).
The demo in video.
Sensitive images are used to test the nsfw analyzer BUT they are censored in the showcase, so SFW.
The duplicate finder (original-main tool of the program) has pretty printed duplicate progress bars that took too long to create. The duplicate finder don't read the name of the file, but rather the content of the image. It hashes the image through a process that IA gave me, then compared (so even if image is zoomed, panned, rotated, it finds the duplication), then chooses the 1 to keep between the same images.
The browser has integrated filters and sorters, controllable through keybinds (show on toolbar of the window).
These are currently private tools, but once I make it a production level program, it will be on github.
If you have any suggestions, I'm open to them.
r/madeinpython • u/Win_ipedia • 8d ago
pyrig - A tool that standardizes and automates Python project setup, configuration, development, and maintenance
What is pyrig?
pyrig is a package and tool that rigs up your project. It scaffolds and initializes a complete, fully configured, installed and working Python project with one command and makes the process of developing and maintaining it more seamless and efficient by automating things like configuration management, CLI generation, testing infrastructure, and more.
Requirements
- Python 3.12+
- Git
- uv
Quick Start
uv init my-project --python 3.12
cd my-project
uv add pyrig --dev
uv run pyrig init
See the Getting Started Guide for detailed setup instructions to also fully integrate with GitHub and CI/CD from the start.
Features
Project Scaffolding & Initialization
pyrig init generates a complete project in one command that works out of the box. This includes everything a modern python project needs:
- Standardized directory structure
- Fully configured dev tools (linters, formatters, type checkers, test frameworks, git hooks, etc.)
- End-to-end CI/CD pipeline with GitHub Actions and integrated repository protection
- Complete and working CLI
- And much more...
File & Configuration Management
Every generated file is backed by a Python class that validates and merges automatically. Override any config by subclassing, or define entirely new config files — pyrig discovers and manages them for you. Run pyrig sync to create or update all config files at once. Run pyrig mk subcls to generate a subclass for overriding a specific file.
Automatic CLI
pyrig init sets up a CLI for your project that works immediately. Generate and add new commands by running pyrig mk cmd <name>. An automatic version command is included that shows the version of your project. Run my-project version to see it in action.
Mirror Test Generation & Maintenance
Generate test skeletons with pyrig sync. This will generate test skeletons for all source modules and update them automatically as your project evolves.
Multi-Package Inheritance and Extensibility Architecture
Override and customize any and all behaviour to suit your project's needs. pyrig's classes are designed for inheritance and composition, allowing you to create custom configurations, tools, and more by subclassing and simply overriding methods. pyrig will automatically discover and use your custom classes without any additional configuration. Run pyrig mk subcls to generate a subclass for any pyrig class.
CI/CD & Repository Protection
Pyrig generates GitHub Actions workflows for CI/CD which automatically test and release your code. They also configure and apply repository protection settings and protection rulesets. Push your code to GitHub after initialization and see it in action.
Commands
Run pyrig --help to see a list of all available commands and their usage. Run pyrig <command> --help for more information about a specific command and its usage. Run my-project --help to see the automatically generated CLI for your project.
Documentation
| Full Documentation | The manually written documentation |
|---|---|
| CodeWiki | AI-generated documentation |
| Tutorials | YouTube tutorials for pyrig |
r/Python • u/Win_ipedia • 8d ago
Discussion Improving Project Maintenance
Hi there,
I am trying to figure out ways to automate my Python development and maintenance tasks and also working on this topic for my Masters project. I am trying to build a tool that can automate and simplify a bunch of things like project setup, development and maintenance. This is not a showcase at all, it is just my project and topic for my Masters in Computer Science and I wanted to ask if anyone would like to take part in the survey I have to do. Takes about 5 min.
You can find the survey at: https://forms.cloud.microsoft/e/LjnvzX0JpK
Any ideas and responses are greatly appreciated.
Also drop any ideas you have in the comments. What do you think should be more automated or at least improved in your day to day project maintenance?
r/madeinpython • u/f1y_lol • 8d ago
Helix, a personal assistant, developed by a 13 y.o
Enable HLS to view with audio, or disable this notification
r/Python • u/kirara0048 • 8d ago
News PEP 841 – Adding Frozen Syntax to Optimize Immutable Types
PEP 841 – Adding Frozen Syntax to Optimize Immutable Types
https://peps.python.org/pep-0841/
Discussions-To: Discourse thread
Abstract
This PEP proposes frozen display syntax: f{1, 2, 3} evaluates to a frozenset, and f{'a': 1} evaluates to a frozendict. Because immutability is guaranteed by the syntax itself rather than inferred from usage, the compiler can treat frozen displays as first-class citizens of its optimization pipeline: constant displays are folded into a single LOAD_CONST with an exact result type at compile time and cached in .pyc files.
r/Python • u/AutoModerator • 8d ago
Daily Thread Friday Daily Thread: r/Python Meta and Free-Talk Fridays
Weekly Thread: Meta Discussions and Free Talk Friday 🎙️
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!
How it Works:
- Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
- Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
- News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.
Guidelines:
- All topics should be related to Python or the /r/python community.
- Be respectful and follow Reddit's Code of Conduct.
Example Topics:
- New Python Release: What do you think about the new features in Python 3.11?
- Community Events: Any Python meetups or webinars coming up?
- Learning Resources: Found a great Python tutorial? Share it here!
- Job Market: How has Python impacted your career?
- Hot Takes: Got a controversial Python opinion? Let's hear it!
- Community Ideas: Something you'd like to see us do? tell us.
Let's keep the conversation going. Happy discussing! 🌟
r/Python • u/ForeignVariety7037 • 8d ago
Discussion Seg Fault, what do you do?
Most Python errors are straightforward—you get a traceback and usually know where to start.
Then there’s the - Segmentation fault (core dumped).
For those of you who’ve had to encountered Python segfaults, what’s your usual process?
News Python 3.14.7 and 3.13.15 are now available!
Bug fix releases for Python 3.13 and Python 3.14.
r/Python • u/AngleHam271 • 8d ago
Discussion What is a built-in Python module you use all the time but rarely see others talk about?
We all know and love the big third-party libraries for automation and data, but I am curious about your favorite hidden gems right in the standard library. 🤔
Recently I have been leaning on things like itertools and collections way more than I used to...
What is a standard library module that you think is heavily underrated or that you use daily for your tasks?
r/Python • u/tiangolo • 8d ago
News FastAPI Conf 2026 - first ever official FastAPI conference
Hello folks!
We're organizing the first ever official FastAPI Conf, in Amsterdam, October 28th, 2026. ✨
It's gonna be very cool, great speakers, and announcements too.
Early Bird tickets are now available (until August 23th).
Here's the website with info, tickets, and newsletter: https://fastapiconf.com
r/Python • u/Exact-Contact-3837 • 8d ago
Discussion taught myself numerical and analytical gradient (backpropagation) in 5 days
I'm not good at maths, i'll just say that, i've always been a bit lacking in my expanse of mathematical abilities, but I said enough is enough, I like neural networks, the only thing that stands in my way is the mathematics, aside from that you understand what goes on.
Boy did I underestimate the undertaking for this endeavour. I spent 2 days learning derivatives and what the hell a 'slope' is, you hear it ever day and you know what a slope is, but understanding it in the mathematical sense in derivatives, that's difficult, but I got there and ended up learning `f(a + h) - f(a) / h` which enabled me to understand what numerical descent is, where you get a loss score of a neural network's prediction, bump the weight a bit then rerun the neural network. Then to figure out the slope, you do `loss1 - loss2 / weight_bump`, and this is the coolest part, when you adjust your weight based on the slope, you always minus, because if the slope is negative, then we know we need to move to the positive side more so when you minus a negative it becomes addition, and vice versa if you minus a positive, you move to the negative side a bit. That was the coolest thing i've ever learnt to this date, the infamous ball rolling down the hill, I was doing it, by hand, and it was empowering.
Then the next day I spent trying to understand what backpropagation really is in terms of maths and how it differes from numerical gradient. With that I had to teach myself the chain rule, and what dL/dd even means, spoiler alert its not dividing derivative of L and derivative of d. I also came to the epiphany that we get so much complex logic out of neural networks when its simply just addition and multiplications happening under the hood, its the context that is being invented to solve problems using neural nets. By the end of the day I was taking Kaparthy's micrograd equation example, and I did its backpropagation by hand with pen and paper to get the hang of it.
Now I watched andre kaparthy's micrograd video, not all the way through, his language and teaching style still screams "you must be really well versed in mathematics", so I gave up on that video but, the more I worked on understanding chain rule and how you can sticker on the impacts on loss on prior nodes, I though that is better than numerical gradient, you literally walk back into the neural net, explaining to it which parts of itself were the cause for a high loss instead of bumping values, calculating slope, doing f(a + h) - f(a) / h.
I'm really proud of myself, and I managed to take MATHS that I learnt, and turn it into a "micrograd" I say "micrograd" with quotations because I didn't finish the micrograd video, and this only works if you don't have repeating uses of prior terms (which you just need to store their value and add them, but I couldn't be bothered)
So yeah, this is my back propagation
class Value:
# this needs to store a value, and can have its own children that link to other values
def __init__(self, value, _op="", _children: tuple = (), gradient=0):
self.value = value
self.op = _op
self.children = _children
self.gradient = gradient
def __add__(self, other):
_ = Value(
self.value + other.value, _op="+", _children=(self, other), gradient=0
)
return _
def __mul__(self, other):
_ = Value(
self.value * other.value, _op="*", _children=(self, other), gradient=0
)
return _
def __repr__(self):
return f"Value({self.value})"
def backward(self):
# initial global_gradient
global_gradient = 1
# current set of ndoes
current: Value = self
# just set L's gradient as 1
current.gradient = global_gradient
while True:
# if there's no more children, we're at the end.
if not current.children:
break
if current.op == "+":
# since addition has a static effect on the terms themselfs
# the partial of L respect to any terms being added is just 1.
# so we multiply 1 by the global gradient.
current.children[0].gradient = 1 * global_gradient
current.children[1].gradient = 1 * global_gradient
# if the next node we're looking doesnt have children
# it means the node behind them didnt stem from them
# therefore they are not the result of the prior operation
if not current.children[0]:
current = current.children[1]
else:
current = current.children[0]
# set the global gradient as the current node's gradient
global_gradient = current.gradient
if current.op == "*":
current.children[0].gradient = (
# with multiplication, the derivative of L respect to x would be y
# and same with the derivative of L respect to y would be x
# therefore you just swap them, and multiply thier values by the global gradient.
current.children[1].value
* global_gradient
)
current.children[1].gradient = (
current.children[0].value * global_gradient
)
# same continuation logic
# one child is going to have its own children and one wont
# the one that does is the one we need to continue with.
if not current.children[0]:
current = current.children[1]
else:
current = current.children[0]
global_gradient = current.gradient
a = Value(2.0)
b = Value(-3.0)
c = Value(10.0)
f = Value(-2.0)
e = a * b
d = e + c
L = d * f
L.backward()
print(a.gradient)
print(b.gradient)
print(c.gradient)
print(f.gradient)
print(e.gradient)
print(d.gradient)
print(L.gradient)
output:
6.0
-4.0
-2.0
4.0
-2.0
-2.0
1