/r/Python
If you have questions or are new to Python use r/LearnPython
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
Online Resources
Five life jackets to throw to the new coder (things to do after getting a handle on python)
PyMotW: Python Module of the Week
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
/r/Python
Hey everyone! In the spirit of release early, release often, I wanted to post to Reddit and Hacker News (for the first time ever!) about an idea of mine. Okay, so it's not a very original idea. It is however a missing gap in the Python ecosystem for learning and introduction to the language.
Check out the Tour of Go if you're not familiar with this concept already. The general idea is an in-browser interactive learning playground. (An in-browser REPL, if you will).
It needs more slides, it needs bugfixes and improvements overall, but the basic concept is here. The sandbox was implemented using code from healeycodes.com and ChatGPT did much of the other initial heavy lifting for me (I am a backend engineer by trade, my front-end skills are extremely rusty.)
The code is here: https://github.com/jadedragon942/tour_of_python/
Disclaimer: it is nothing too fancy.
My long-term lofty goal is to build this and hand it off to python.org if possible/feasible.
Contributors/volunteers/feedback/opinions are of course welcome!
I wanted to share Pyttings, a lightweight Python settings manager with namespacing, modular files, and automatic type parsing. It’s inspired by Django’s settings but designed to be minimal and flexible.
GitHub: https://github.com/ruitcatarino/pyttings
Pyttings simplifies application configuration by allowing you to:
PYTTING_
) to avoid conflicts.PYTTING_ENV_PREFIX
.PYTTING_SETTINGS_MODULE
.Pyttings is production-ready and ideal for:
pydantic-settings
or Django-style settings.Compared to Django’s settings, Pyttings is framework-agnostic and much lighter.
Compared to pydantic-settings
, Pyttings has:
Would love your feedback! Let me know what you think or if you have suggestions.
Hey everyone! I’ve developed KEGOMODORO, an open-source productivity tool designed to enhance time management! It's a customizable Pomodoro and Stopwatch timer that anyone can personalize and extend to suit their needs.
KEGOMODORO allows users to manage their time effectively with Pomodoro and Stopwatch modes. It features an easy-to-use interface, supports quick note-taking, logs your work hours, and even shows a graph to track your productivity over time. It also comes with a Behelit Mode, inspired by Berserk, for a fun, thematic countdown timer.
KEGOMODORO differs from traditional Pomodoro timers in that it is highly customizable. You can change themes to fit your personal style, and the app offers a unique Berserk-themed Behelit Mode that is a fun twist on productivity tools. Additionally, its lightweight design makes it easier to use without extra dependencies, unlike many Pomodoro apps that can be bulky or require complex setups. Plus, it’s built in Python, so it’s simple to modify and extend, especially for Python developers!
KEGOMODORO allows you to easily create custom themes to suit your style. The main goal of the app is flexibility and personalization—below are just a few examples of how it can be customized.
Feel free to fork, modify, and contribute to the project! I built it in Python to make it accessible for anyone to understand and tweak as needed.
🔗 GitHub: https://github.com/Kagankakao/KEGOMODORO
If you're looking for a fun and efficient way to improve your time management and productivity, check it out! 🚀🔥 Fork it and contribute if you're interested!
I normally use trinket.io to embed Python 3 codes into my website but I recently discovered that it has a 60-second time limit for running code. Do you have any other online options similar to Trinket?
Recently I had the opportunity to talk about the FastAPI under the hood at PyCon APAC 2024. The title of the talk was “FastAPI Deconstructed: Anatomy of a Modern ASGI Framework”. Then, I thought why not have a written version of the talk. And, I have decided to write. Something like a blog post. So, here it is.
https://rafiqul.dev/blog/fastapi-deconstructed-anatomy-of-modern-asgi-framework
Python 3.13 introduces an experimental option to disable the Global Interpreter Lock (GIL), something the community has been discussing for years.
I wanted to see how much of a difference it actually makes, so I explored and ran benchmarks on CPU-intensive workloads, including:
🔍 Key takeaways from my benchmarks:
📖 I wrote a full blog post with my findings and detailed benchmarks: https://simonontech.hashnode.dev/exploring-python-313-hands-on-with-the-gil-disablement
What do you think? Will No-GIL Python change how we use Python for CPU-intensive and parallel tasks?
Hey devs! Sharing my first project - an AI-powered PDF Report Generator! 🐍📊
Please checkout GitHub Repo for Tutorial Video https://github.com/bobinsingh/PedroReports-LLM-Powered-Report-Tool
I recently switched my career from life sciences to coding, and I wanted to create something useful after learning. So I built a tool that generates professional data analysis PDF reports from any tabular dataset. You just need to input what you want to analyze, and it does the job for you. Thought you might find it interesting!
The workflow is simple: feed it your data, and it handles everything from visualization to creating a fully formatted report with AI-generated descriptions. No more manual report writing! 🎉
Check it out on Github! Happy to answer any questions.
Hey everyone!
I wanted to share a Python program I made fairly recently.
FFE is a TUI (Command Line) Tool to make it easier to share files with your friends without anyone else seeing them. Some features currently present are:
The target audience for FFE is.. anyone. FFE is built so it's easy to use, so everyone, even your grandma, can use it.
The only requirement is a Windows PC with Windows 7 or newer, and the huge amount of storage space that is ~70 MB (if you install the Visual C++ Redist, which isn't required on Windows 10 and above).
FFE is different to other encryption programs, because instead of just using a password to encrypt files, it uses a Key File that you send to anyone that should be able to access your files, and then you just send each other files as many times as you want!
Oh yeah, and FFE is completely open-source, so you can look at all the code directly on GitHub.
Visit the GitHub if you want to download it, or if you would like to contribute.
Built with Python 3.13+
Have fun encrypting!
Hey folks! 👋
I wanted to share a personal tool I built for my note-taking workflow that might be interesting for terminal enthusiasts and markdown lovers. It's called Pinkmess, and it's a CLI tool that helps manage collections of markdown notes with some neat AI features.
Pinkmess is a command-line tool that helps manage collections of markdown notes with AI capabilities. It:
This is explicitly a personal tool I built for my own note-taking workflow and for experimenting with AI-powered note organization. It's **not** intended for production use, but rather for:
Unlike full-featured PKM systems (Obsidian, Logseq, etc.), Pinkmess:
Install it from PyPI:
$ pip install pinkmess
Create and edit a note
$ pinkmess note create
$ pinkmess note edit
Generate AI metadata:
$ pinkmess note generate-metadata --key summary
$ pinkmess note generate-metadata --key tags
GitHub: https://github.com/leodiegues/pinkmess
Built with Python 3.10+ and Pydantic.
Looking forward to your feedback! 🌸
Happy note-taking! 🌸
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! 🌟
What My Project Does
Basically I was making a lot of automations for my clients and developed a toolset that i am using for most of my automation projects. It is on Python + Playwright (for ui browser automation) + requests (covered with base modules for API automation) + DB module. I believe it maybe useful for someone of you, and I’ll appreciate your stars/comments/pull-requests:
https://github.com/eshut/Inject-Framework
I understand it may be very «specialized» thing for someone, but if you need to automate something like website or api - it makes the solution structured and fast.
Feel free to ask your questions.
Target Audience
Anyone who is looking for software automation on Python for websites or some API
Comparison
I believe there are similar libraries on Typescript as codecept and maybe something similar on python , but usually it is project specific
End to end software test automation has long been a technical process lagging with the development cycle. Also, every time engineering team updates the UI or the platform (Salesforce/SAP) goes through an update , the maintenance of the test automation framework, pushed it further behind the delivery cycle. So we created an open source end to end testing agent, to solve for test automation.
High level flow:
Write natural language tests -> Agent runs the test -> Results, screenshots, network logs, and other traces output to the user.
Installation:
pip install testzeus-hercules
Sample test case for visual testing:
Feature: This feature displays the image validation capabilities of the agent Scenario Outline: Check if the Github button is present in the hero section Given a user is on the URL as
https://testzeus.com
And the user waits for 3 seconds for the page to load When the user visually looks for a black colored Github button Then the visual validation should be successful
Architecture:
We use AG2 as the base plate for running a multi agentic structure. Tools like Playwright or AXE are used in a REACT pattern for browser automation or accessibility analysis respectively.
Capabilities:
The agent can take natural language english tests for UI, API, Accessibility, Security, Mobile and Visual testing. And run them autonomously, so that user does not have to write any code or maintain frameworks.
Comparison:
Hercules is a simple open source agent for end to end testing, for people who want to achieve insprint automation.
There are multiple testing tools (Tricentis, Functionize, Katalon etc) but not so many agents
There are a few testing agents (KaneAI) but its not open source.
There are agents, but not built specifically for test automation.
On that last note, we have hardened meta prompts to focus on accuracy of the results.
If you like it, give us a star here: https://github.com/test-zeus-ai/testzeus-hercules/
Pixerise is a high-performance 3D software renderer that proves Python can be blazing fast when done right.
What My Project Does
Pixerise is a pure Python 3D software renderer that performs all rendering on the CPU. It takes 3D models, applies transformations, lighting, and perspective projection, then rasterizes them to create a 2D image - all without requiring a GPU. Think of it as building a mini game engine from scratch, but with Python's readability and Numba's speed.
Target Audience
This project serves multiple audiences:
While it's not meant to replace production-grade engines like Unity or Unreal, it's robust enough for:
Comparison
Here's how Pixerise compares to other Python 3D solutions:
🆚 PyOpenGL
🆚 VPython
🆚 Other Pure Python Renderers
🆚 Professional Game Engines
What makes it fast?
Key Features:
🎨 Rendering Pipeline
🛠 Developer-Friendly
🚀 Performance Optimized
The renderer achieves impressive performance by leveraging Numba's just-in-time compilation for the performance-critical rendering pipeline. This approach combines Python's ease of use with near-C performance for numerical computations.
If you find this project interesting, I'd really appreciate your support! Since it just went public today, every star helps increase visibility and encourages further development.
Try it yourself: https://github.com/enricostara/pixerise
Hey everyone,
I’m currently working on a Python script using the Bioformats library to process .lif
files. My goal is to extract everything contained in these files (images and .xml
metadata), essentially replicating what the Leica software does when exporting data.
So far, I’ve managed to extract all the images, and at first glance, they look identical. However, when comparing pixel by pixel, they are actually different. I suspect this is because the Leica software applies a LUT (Look-Up Table) transformation to the images, and I haven't accounted for that in my extraction.
Another issue I’m facing is the .xml
metadata file. The one I generate is completely different from what Leica produces, and I can’t figure out what I’m missing.
Has anyone encountered a similar issue? Does Bioformats handle LUTs differently, or should I be using another library? Any suggestions on how to properly extract the correct images and metadata?
I’d really appreciate any insights! Thanks in advance.
Hey folks! I recently created Kreuzberg, a Python library that makes text extraction from PDFs and other documents simple and hassle-free.
I built this while working on a RAG system and found that existing solutions either required expensive API calls were overly complex for my text extraction needs, or involved large docker images and complex deployments.
Key Features:
This library is perfect for developers working on RAG systems, document processing pipelines, or anyone needing reliable text extraction without the complexity of commercial APIs. It's designed to be simple to use while handling a wide range of document formats.
from kreuzberg import extract_bytes, extract_file
# Extract text from a PDF file
async def extract_pdf():
result = await extract_file("document.pdf")
print(f"Extracted text: {result.content}")
print(f"Output mime type: {result.mime_type}")
# Extract text from an image
async def extract_image():
result = await extract_file("scan.png")
print(f"Extracted text: {result.content}")
# Or extract from a byte string
# Extract text from PDF bytes
async def process_uploaded_pdf(pdf_content: bytes):
result = await extract_bytes(pdf_content, mime_type="application/pdf")
return result.content
# Extract text from image bytes
async def process_uploaded_image(image_content: bytes):
result = await extract_bytes(image_content, mime_type="image/jpeg")
return result.content
Unlike commercial solutions requiring API calls and usage limits, Kreuzberg runs entirely locally.
Compared to other open-source alternatives, it offers a simpler API while still supporting a comprehensive range of formats, including:
Check out the GitHub repository for more details and examples. If you find this useful, a ⭐ would be greatly appreciated!
The library is MIT-licensed and open to contributions. Let me know if you have any questions or feedback!
ive seen some people use python to program their christmas tree lights or some people use it to automate web scraping, web games so what are some other uses that youve seen
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! 🌟
Hi folks,
I'm not sure I saw anything about it on the sub so forgive me if that's the case.
Michael was a singular voice in the Python community, always fighting to help people see things from a different direction. His passion was radiating. He'll be missed.
Here is a beautiful message from Nicholas H.Tollervey.
I’m excited to share with you my first Python code: Football Tracking Data Visualization. As someone passionate about both programming and sports—especially the NFL—this project has allowed me to combine these interests and dive into real-time data analysis and visualization.
This repository uses football player tracking data, collected through the NFL Big Data Bowl, to create interactive visualizations. The project allows us to see player movements during plays, interpret stats, and observe player interactions on the field. 🎯
This is about my previous post on https://python.gatecode.org . I am not sure why I cannot reply the previous post, so I created this so that I can follow up the discussion. (Please do not remove or block this, community manager. It is some technical discussion.) I am just trying to provide a convenient tool for python developers but somebody says the resulting file could be easily undo. I just uploaded a sample file here: https://github.com/shadowwalker2718/gatecode/blob/main/sample/my_valuable_code
I wonder how it can be `easily undo`. Can anybody help to `undo` it please? If yes, could you please show me the source code? It will be really appreciated if you could. Thanks.
Attention Python developers! 🐍✨ Tired of the tedious setup process for new projects? Say hello to 'aasetpy' - your new best friend for kickstarting Python projects with ease!
Whether you are willing to test out a new AI tool or create a new backend for your client, you would need to run multiple commands to enable a virtual environment and then the dependencies.
Whet my project does:
With just one command, `aasetpy` sets up everything you need: virtual environments, codebase structure, REST API configuration, environment variables, initial git commit, resource usage tracking, logging, containerization, and more! It's like having a personal assistant for your development workflow, ensuring your projects are production-ready and scalable from the very start.
Target Audience: All the Python Developers in the world.
Ready to revolutionize your project setup? Check out the 'aasetpy' repository at https://github.com/aadarshlalchandani/aasetpy and see the magic for yourself! We're always open to contributions, so if you have ideas to make the starting point even better, don't hesitate to jump in. Let's make Python project initialization a breeze together! 🚀💻
Love the tool? Smash that star button and share it with your coding crew! ⚡️🤝
Every time I wanted to use LLMs in my existing pipelines the integration was very bloated, complex, and too slow. This is why I created a lightweight library that works just like scikit-learn, the flow generally follows a pipeline-like structure where you “fit” (learn) a skill from sample data or an instruction set, then “predict” (apply the skill) to new data, returning structured results.
High-Level Concept Flow
Your Data --> Load Skill / Learn Skill --> Create Tasks --> Run Tasks --> Structured Results --> Downstream Steps
Installation:
pip install flashlearn
Learning a New “Skill” from Sample Data
Like a fit/predict pattern from scikit-learn, you can quickly “learn” a custom skill from minimal (or no!) data. Below, we’ll create a skill that evaluates the likelihood of buying a product from user comments on social media posts, returning a score (1–100) and a short reason. We’ll use a small dataset of comments and instruct the LLM to transform each comment according to our custom specification.
from flashlearn.skills.learn_skill import LearnSkill
from flashlearn.client import OpenAI
# Instantiate your pipeline “estimator” or “transformer”, similar to a scikit-learn model
learner = LearnSkill(model_name="gpt-4o-mini", client=OpenAI())
data = [
{"comment_text": "I love this product, it's everything I wanted!"},
{"comment_text": "Not impressed... wouldn't consider buying this."},
# ...
]
# Provide instructions and sample data for the new skill
skill = learner.learn_skill(
data,
task=(
"Evaluate how likely the user is to buy my product based on the sentiment in their comment, "
"return an integer 1-100 on key 'likely_to_buy', "
"and a short explanation on key 'reason'."
),
)
# Save skill to use in pipelines
skill.save("evaluate_buy_comments_skill.json")
Input Is a List of Dictionaries
Whether the data comes from an API, a spreadsheet, or user-submitted forms, you can simply wrap each record into a dictionary—much like feature dictionaries in typical ML workflows. Here’s an example:
user_inputs = [
{"comment_text": "I love this product, it's everything I wanted!"},
{"comment_text": "Not impressed... wouldn't consider buying this."},
# ...
]
Run in 3 Lines of Code - Concurrency built-in up to 1000 calls/min
Once you’ve defined or learned a skill (similar to creating a specialized transformer in a standard ML pipeline), you can load it and apply it to your data in just a few lines:
# Suppose we previously saved a learned skill to "evaluate_buy_comments_skill.json".
skill = GeneralSkill.load_skill("evaluate_buy_comments_skill.json")
tasks = skill.create_tasks(user_inputs)
results = skill.run_tasks_in_parallel(tasks)
print(results)
Get Structured Results
The library returns structured outputs for each of your records. The keys in the results dictionary map to the indexes of your original list. For example:
{
"0": {
"likely_to_buy": 90,
"reason": "Comment shows strong enthusiasm and positive sentiment."
},
"1": {
"likely_to_buy": 25,
"reason": "Expressed disappointment and reluctance to purchase."
}
}
Pass on to the Next Steps
Each record’s output can then be used in downstream tasks. For instance, you might:
Below is a small example showing how you might parse the dictionary and feed it into a separate function:
# Suppose 'flash_results' is the dictionary with structured LLM outputs
for idx, result in flash_results.items():
desired_score = result["likely_to_buy"]
reason_text = result["reason"]
# Now do something with the score and reason, e.g., store in DB or pass to next step
print(f"Comment #{idx} => Score: {desired_score}, Reason: {reason_text}")
Comparison
Flashlearn is a lightweight library for people who do not need high complexity flows of LangChain.
FlashLearn - Minimal library meant for well defined us cases that expect structured outputs
LangChain - For building complex thinking multi-step agents with memory and reasoning
If you like it, give us a star: Github link
I created two libraries while developing AnchorSCAD (a Python-based 3D model building library) that have been recently released them PyPI:
A wrapper for dataclasses that eliminates boilerplate when composing classes hierarchically:
See it in action in this AnchorSCAD model where it manages complex parameter hierarchies in 3D modeling. anchorscad-core - anchorscad_models/bendy/bendy.py
pip install datatrees
Built on top of datatrees, provides clean XML serialization/deserialization.
pip install xdatatrees
GitHub: datatrees xdatatrees
Ruff, uv and Polars presents themselves as fast tools writter in Rust.
It seems to me that "written in Rust" is used as a marketing argument. It's supposed to mean, it's fast because it's written in Rust.
These tools could have been as fast if they were written in C. Rust merely allow the developpers to write programms faster than if they wrote it in C or is there something I don't get ?
Hi r/Python!
I'm excited to share with you a new small Python package I've developed called Lesley. This package makes it easy to create GitHub-style calendar-based heatmaps, perfect for visualizing time-series data in a clear and intuitive way.
What My Project Does
The package includes three main functions for creating different types of heatmaps:
cal_heatmap: A function for generating a calendar-based heatmap for a given year and data. This will give you the most similar result to GitHub's activity plot.
month_plot: A function for creating a heatmap for a specific month, allowing you to drill down into detailed views of your time-series data.
plot_calendar: A function for plotting the whole year in a single plot, providing an at-a-glance overview of your data.
Target Audience
I have used it on my own project and it is running in production.
Comparison
There's a similar project called July, which is using matplotlib as the underlying backend. I used Altair, which makes it interactive. You can hover over the heatmap and a tooltip will tell you its values.
You can explore the source code on GitHub: https://github.com/mitbal/lesley
And see Lesley in action by trying the demo on this page: https://alexandria-bibliotek.up.railway.app/lesley
Python's simplicity and flexibility come with a trade-off: source code is easily exposed when published or deployed. GateCode provides a secure solution to this long-standing problem by enabling you to encrypt your Python scripts, allowing deployment without revealing your IP(intellectual property) or secret in the source code.
Website: https://www.gatecode.org/
Imagine you’ve developed a proprietary algorithm that you need to deploy to your clients. Using GateCode:
This ensures that your intellectual property is secure while maintaining usability.
Parses Securities & Exchange Commission SGML. Regulatory disclosures submitted to the SEC are first submitted in SGML format, then parsed into individual documents/attachments. Since the SEC has strict rate limits (~5/s), scraping the original submission rather than individual documents is much more efficient.
Software engineers, grad students, and quants. The goal is to reduce code duplication and improve quality for a niche group of users.
There are a few packages to parse sec sgml, but they are not as robust/fast. For instance: SEC-data-parser (python) and edgarWebR (R).
pip install secsgml
from file
parse_sgml_submission(filepath='samples/0000891618-94-000021.txt',output_dir='results')
from content
parse_sgml_submission(content=sgml_content,output_dir='results')
Hey everybody!
It's been a while since the last SimplePyBLE release, so I'm here to share what's new with SimplePyBLE!
Let me introduce you to SimplePyBLE, the Python bindings for SimpleBLE, a cross-platform Bluetooth library specifically designed for use in all kinds of environments with a very simple API that just works, allowing developers to easily integrate it into their projects without much effort, instead of wasting hours and hours on development.
We provide comprehensive functionality support for BLE Central mode, enabling developers to scan and discover nearby BLE devices, handle pairing and connection management of peripherals, and interact with GATT characteristics and descriptors just to name a few. This functionality is fully supported across Windows, Linux, MacOS, iOS and Android.
See for yourself how easy it is to get started by looking at our examples on GitHub.
SimpleBLE is licensed under the Business Source License 1.1 and is trusted by industry leaders across healthcare, automotive, manufacturing, and entertainment. While commercial use requires a license, SimpleBLE is free to use for non-commercial purposes and we gladly offer free licenses for small projects, so don't hesitate to reach out!
Want to know more about SimpleBLE's capabilities or see what others are building with it? Ask away!
TL;DR to keep the automod happy
It's a cross-platform to connect to Bluetooth devices.
Library is production grade, used by companies in multiple industries
Different from bleak in that it doesn't require async and has a simpler API that our users prefer.
What My Project Does
SmolModels is a Python framework that helps generate and test different ML architectures. Instead of manually defining layers and hyperparameters, you describe what you want in plain English, specify input/output schemas, and it explores different architectures using graph search + LLMs to compare performance.
Target Audience
Comparison to Existing Alternatives
Repo & Feedback
It’s still early, and I’d love feedback on whether this is actually useful or just an interesting experiment.
Repo: https://github.com/plexe-ai/smolmodels
Would love to hear thoughts—what would make this more useful for you?
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! 🌟