r/Python • u/johnmcdonnell • Oct 02 '12
TIL you can use a for...else construct in Python! I will certainly be using this henceforth.
r/Python • u/johnmcdonnell • Oct 02 '12
r/Python • u/TheChosenMenace • Jun 06 '25
Genreq – A smarter way to generate requirements file.
What My Project Does:
I built GenReq, a Python CLI tool that:
- Scans your Python files for import statements
- Cross-checks with your virtual environment
- Outputs only the used and installed packages into requirements.txt
- Warns you about installed packages that are never imported
Works recursively (default depth = 4), and supports custom virtualenv names with --add-venv-name.
Install it now:
pip install genreq \
genreq . Target Audience:
Production code and hobby programmers should find it useful.
Comparison:
It has no dependency and is very light and standalone.
r/Python • u/gman1234 • Jul 21 '10
r/Python • u/mraza007 • Jun 11 '24
I have always been curious on how http servers works. Therefore, I decided to write a post on how they work and implementing a simple server in Python.
r/Python • u/Super_Sign_9198 • Aug 19 '25
UVForge is a CLI tool that bootstraps a modern Python project in seconds using uv. Instead of writing config files or copying boilerplate, you just answer a few interactive prompts and UVForge sets up:
src/ project layout
pytest with example tests
ruff for linting
optional Docker and Github Actions support
a clean, ready-to-go structure
Beginners and Advanced programmers who want to start coding quickly without worrying about setup.
Developers who want a “create-react-app” experience for Python.
Anyone who dislikes dealing with templating syntax or YAML files.
It’s not meant for production frameworks, it is just a quick, friendly way to spin up well-structured Python projects.
The closest existing tool is Cookiecutter, which is very powerful but requires YAML/JSON templates and some upfront configuration. UVForge is different because it is:
Fully interactive: answer prompts in your terminal, no template files needed.
Zero config to start: works out of the box with modern Python defaults.
Lightweight: minimal overhead, just install and run.
Would love feedback from the community, especially on what features or integrations you’d like to see added!
Links
GitHub: https://github.com/manursutil/uvforge
r/Python • u/10deeply • Oct 07 '22
I've recently started on Python and was looking at this tutorial until it said to download Pycharm.
And I'm thinking that that Pycharm is just completely different. Sorry if this is a stupid question but I'm very confused.
r/Python • u/Goldziher • Jun 25 '25
Hey everyone! 👋
I just released v2.2.0 of uncomment, a CLI tool that removes comments from source code. It's written in Rust for maximum performance but now easily installable via pip:
pip install uncommentRemoves comments from your code files while preserving important ones like TODOs, linting directives (#noqa, pylint, etc.), and license headers. It can optionally strip doc strings, but doesnt touch them by default.
Why it's different: Uses the tree-sitter ecosystem to properly parse the AST of more than ten programming languages and configuration formats. In fact, this can be further extended to support any number of languages.
Performance: Tested on several repositories of various sizes, biggest being a huge monorepo of over 850k+ files. Since the tool supports parallel processing, it was able to uncomment almost a million files in about a minute.
Use case: Originally built this to clean up AI-generated code that comes with excessive explanatory comments, but it's useful anytime you need to strip comments from a codebase.
# Remove comments from a single file
uncomment file.py
# Preview changes without modifying files
uncomment --dry-run file.py
# Process multiple files
uncomment src/*.py
# Remove documentation comments/docstrings
uncomment --remove-doc file.py
# Remove TODO and FIXME comments
uncomment --remove-todo --remove-fixme file.py
# Add custom patterns to preserve
uncomment --ignore-patterns "HACK" --ignore-patterns "WARNING" file.py
# Process entire directory recursively
uncomment src/
# Use parallel processing with 8 threads
uncomment --threads 8 src/
# Benchmark performance on a large codebase
uncomment benchmark --target /path/to/repo --iterations 3
# Profile performance with detailed analysis
uncomment profile /path/to/repoCurrently the tool supports:
Python (.py, .pyw, .pyi, .pyx, .pxd)
JavaScript (.js, .jsx, .mjs, .cjs)
TypeScript (.ts, .tsx, .mts, .cts, .d.ts, .d.mts, .d.cts)
Rust (.rs)
Go (.go)
Java (.java)
C (.c, .h)
C++ (.cpp, .cc, .cxx, .hpp, .hxx)
Ruby (.rb, .rake, .gemspec)
YAML (.yml, .yaml)
HCL/Terraform (.hcl, .tf, .tfvars)
Makefile (Makefile, .mk)
The tool is helpful for developers and DevOps, especially today when AI agents are increasingly writing a lot of code and leaving a lot of comments in their trail.
I'm not aware of another tool that does this, that's why I made it - I needed this tool.
Here is the repo: https://github.com/Goldziher/uncomment
I would love to hear your feedback or use cases!
r/Python • u/JohnettaHarned • Sep 22 '15
r/Python • u/hatchet-dev • Jun 10 '24
Hey everyone - I wrote up a blog post on the problems that we've encountered using Celery: https://docs.hatchet.run/blog/problems-with-celery
Our issues with the Celery project were part of the reason why we started Hatchet.
Would love to hear comments or feedback!
r/Python • u/helpdeveu • May 27 '19
r/Python • u/Successful-Moment594 • Sep 26 '26
Most LLM APIs give you back text, and then you write code to guess whether it meant "yes". Decision models like Jev skip that step. You send some text plus a few questions, and you get back typed answers with probabilities.
Here's a complete request with plain httpx. It asks two questions about one customer message: a yes/no question and a choice question. It uses the free practice endpoint from my course, so you can run it without a key:
import httpx
response = httpx.post(
"https://algoholic.io/api/v1/learn/alpha/decisions",
headers={"Authorization": "Bearer free"},
json={
"model": "system-one-models",
"state": "I was charged twice for my order last week. Please refund the extra payment.",
"questions": {
"refund": {"type": "noul", "instructions": "Does the customer ask for money back?"},
"team": {
"type": "choice",
"instructions": "Which team should handle this message?",
"criteria": {
"billing": "Charges, payments and refunds",
"technical": "The website or app not working",
"delivery": "Parcels, shipping and returns",
},
},
},
},
)
answers = response.json()["answers"]
print(answers["refund"])
print(answers["team"])Output:
{'noul': 0.99, 'type': 'noul'}
{'choice': 'billing', 'confidence': 1, 'probabilities': {'billing': 1, 'delivery': 0, 'technical': 0}, 'type': 'choice'}The yes/no answer (noul) is a probability, 0.99 here, so you choose the threshold yourself. Putting refund >= 0.8 in an if is the whole routing logic. When I ran three different messages, they scored 0.99, 0.29 and 0.03, so only the real refund request got through.
I made a 1-hour tutorial that builds this from zero: reading the JSON, choice and score questions, several questions in one request, then the Python SDK with typed answers: https://youtu.be/iiPWySCdYQg
Do let me know if you have any doubts or feedback :)
r/Python • u/metaperl • May 05 '22
I just cancelled my PyCharm subscription after being a faithful purchaser of the Pro version for 5 years. I really liked the ability to navigate complex object hierarchies.. it saved my bacon once... but I refuse to use this thing on a personal basis and deal with 3-10 minutes of "scanning.... indexing ....." .
later JetBrains.
r/Python • u/students-life • May 28 '13
r/Python • u/mdipierro • Aug 12 '10
r/Python • u/andre-felipe-dias • Feb 14 '22
Starting a new Python project doesn't have to be a challenge because the basic needs are always the same even for different types of projects. This article presents how to create a perfect initial base that can be used for any Python project.
https://blog.pronus.io/en/posts/python/how-to-set-up-a-perfect-python-project/
r/Python • u/sassydesigner • Jun 25 '21
r/Python • u/SeleniumBase • Sep 19 '25
You've likely seen it before: The with keyword, which is one way of using Python context managers, such as in this File I/O example below:
with open('my_file.txt', 'r') as f:
content = f.read()
print(content)Python context managers provide a way to wrap code blocks with setUp and tearDown code that runs before and after the code block. This tearDown part can be useful for multiple reasons, such as freeing up resources that have been allocated, closing files that are no longer being read from (or written to), and even quitting browsers that were spun up for automated testing.
Creating them is simple. Let's create a simple context manager that displays the runtime of a code block:
import time
from contextlib import contextmanager
@contextmanager
def print_runtime(description="Code block"):
start_time = time.time()
try:
yield
finally:
runtime = time.time() - start_time
print(f"{description} ran for {runtime:.4f}s.")Here's how you could use it as a method decorator:
@print_runtime()
def my_function():
# <CODE BLOCK>
my_function()Here's how you could use it within a function using the with keyword:
with print_runtime():
# <CODE BLOCK>And here's a low-level way to use it without the with keyword:
my_context = print_runtime()
my_object = my_context.__enter__()
# <CODE BLOCK>
my_context.__exit__(None, None, None)As you can see, it's easy to create and use Python context managers. You can even pass args into them when configured for that. In advanced scenarios, you might even use context managers for browser automation. Example:
from seleniumbase import SB
with SB(incognito=True, demo=True, test=True) as sb:
sb.open("https://www.saucedemo.com")
sb.type("#user-name", "standard_user")
sb.type("#password", "secret_sauce")
sb.click("#login-button")
sb.click('button[name*="backpack"]')
sb.click("#shopping_cart_container a")
sb.assert_text("Backpack", "div.cart_item")That was a simple example of testing an e-commerce site. There were a few args passed into the context manager on initialization, such as incognito for Chrome's Incognito Mode, demo to highlight browser actions, and test to display additional info for testing, such as runtime.
Whether you're looking to do simple File I/O, or more advanced things such as browser automation, Python context managers can be extremely useful!
r/Python • u/No-Mess-8224 • Feb 05 '26
ZYRON is a personal, local-first assistant that runs entirely on my own laptop and lets me retrieve files based on context instead of filenames. For example, I can ask it for “the PDF I was reading last Tuesday evening” and get the correct file without manually searching folders.
The system also exposes a private, text-based interface to my laptop so I can query its current state (for example, what I was working on recently) from my phone. Everything runs locally. No cloud services, no external data storage, and no file history sent to third parties.
The project is written primarily in Python, which handles file indexing, context tracking, system queries, and communication with a locally running language model.
This is not a production tool. It’s a personal / experimental project built for learning and daily personal use.
It’s intended for developers who are interested in:
local-first software
Python-based system utilities
experimenting with LLMs without cloud dependencies
privacy-preserving personal automation
Most existing solutions rely on cloud services and require sending file metadata or usage history to external servers. Operating systems also depend heavily on exact filenames or folder locations.
This project differs by:
running entirely locally
using Python to reason over context and usage history, not just file paths
avoiding any vendor cloud, accounts, or data synchronization
The focus is not speed or scale, but privacy and personal control.
GitHub: LINK
r/Python • u/BeamMeUpBiscotti • Jun 08 '26
Mypy, Pyrefly, Pyright, ty, Zuban, and possibly more that will come in the future... how are library maintainers expected to cope?
TL;DR: If you're a library maintainer, prioritise running as many type-checkers as possible on your test suite. Run at least one on your source code.
In the, we share our reasoning about why we think this approach is best, along with a case study for the Polars package.
Full blog post: https://pyrefly.org/blog/too-many-type-checkers/
I'd love to hear from the community:
What's the biggest friction around running multiple type checkers in CI?
Have you ever used a package that doesn't play nicely with your type checker because it depends on the implementation details of a different type checker?
r/Python • u/CreativePunch • Mar 20 '14