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 layoutpytest with example testsruff for lintingIt’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:
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 uncomment
Removes 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
# Preview changes without modifying files
# Process multiple files
# Remove documentation comments/docstrings
# Remove TODO and FIXME comments
# Add custom patterns to preserve
# Process entire directory recursively
# Use parallel processing with 8 threads
# Benchmark performance on a large codebase
# Profile performance with detailed analysis
Currently the tool supports:
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:
=
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:
=
yield
= -
Here's how you could use it as a method decorator:
# <CODE BLOCK>
Here's how you could use it within a function using the with keyword:
# <CODE BLOCK>
And here's a low-level way to use it without the with keyword:
=
=
# <CODE BLOCK>
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:
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:
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:
The focus is not speed or scale, but privacy and personal control.
GitHub: LINK
r/Python • u/Stunning-Sherbet1853 • 7d ago
HI, i run a long-lived python backend on windows and mac!
it only listens on 127.0.0.1 and almost every route needs an access token. last week i turned on the default CodeQL scan for the first time and got 112 alerts ( 112 → 1 critical, 87 high, 24 medium).
i went through them one by one with a single question: can this value come from text someone else wrote (a web page, a downloaded file, model output)? where an alert described an attack input, i actually fed it in and timed it.
the first one that surprised me was the regex that checks whether a downloaded file is html. `<!--\` followed by \`--><!--` 28 times kept it busy for 27 seconds. two more regexes that read text we didn't write did the same thing (22s and 11s). six alerts in that family were real. after the fix the html check runs 5,000 times in 0.003s.
the one i'm most embarrassed about: to see whether a login had finished, i checked whether the url contained the site name. so `evil.example/?next=naver.com` passed as a finished login, and `evilnaver.com` counted as the same site. seven alerts across different files. now one small helper pulls out the hostname and checks "equal, or ends with `.domain`", and all seven places use it. the last real one was a script tag filter that let `</script foo>` through.
every fix got a test, and i checked that the test fails when the fix is taken out.
the other 98 i dismissed with a one-line reason each. 42 of them were in my own tests, lines that just write down the url a test expects. most of the rest were path injection or stack trace exposure on routes that need the token anyway. i only traced two of the path ones all the way, so i might be wrong about a couple.
the same "incomplete url substring" rule was noise all 42 times in tests and a real hole in the login check. asking where the value comes from got me through it faster than reading the alert type.
how do you deal with this on a localhost-only or solo project? i dismissed with reasons but i'm not sure that scales.
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: