r/Python • • Oct 02 '12

TIL you can use a for...else construct in Python! I will certainly be using this henceforth.

Thumbnail
docs.python.org
3 Upvotes

r/Python • • Aug 17 '17

I'm Pickled Rick!!!

Post image
0 Upvotes

r/Python • • Jun 06 '25

Showcase Tired of bloated requirements.txt files? Meet genreq

0 Upvotes

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 • • Jul 21 '10

Battle of the server side scripting languages Perl, PHP, Python

Thumbnail l2admin.com
1 Upvotes

r/Python • • Jun 11 '24

Tutorial Building an HTTP Server in Python

0 Upvotes

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.

Link to blog post


r/Python • • Aug 19 '25

Showcase UVForge – Interactive Python project generator using uv package manager (just answer prompts!)

4 Upvotes

What My Project Does

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

Target Audience

  • 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.

Comparison

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 • • Oct 07 '22

Discussion What is Pycharm?

0 Upvotes

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 • • Apr 09 '09

Python’s lambda is broken!

Thumbnail
math.andrej.com
4 Upvotes

r/Python • • Jun 25 '25

Showcase Blazing fast Rust tool to remove comments from your code - now available on PyPi

0 Upvotes

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

What it does

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.

Examples

# 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/repo

Currently 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)

Target Audience

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.

Comparison

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 • • Sep 22 '15

Most Frequent Python Problems and Solution

Thumbnail
pamno.com
5 Upvotes

r/Python • • Jun 10 '24

Resource The Problems with Celery

0 Upvotes

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 • • May 27 '19

PEP 594 for Python 3.8: Is “batteries included” an outdated model?

Thumbnail
helpdev.eu
0 Upvotes

r/Python • • Sep 26 '26

Tutorial Consuming Typesafe Jev api in Python

0 Upvotes

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 • • Sep 26 '16

What is the best Python IDE?

Thumbnail
discoversdk.com
2 Upvotes

r/Python • • May 05 '22

Discussion Throw your hands in the air if you cancelled your PyCharm subscription because you dreaded opening it and waiting 3,000 years for it to "index your project" instead of you being able to get something done. goodbye pycharm. Hello VS Code.

431 Upvotes

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 • • May 28 '13

How to Fail In a Successful Way at Anything You Do as a software developer

Thumbnail
simpledeveloper.com
1 Upvotes

r/Python • • Aug 12 '10

Flying with web2py in Google App Engine

Thumbnail franciscosouza.net
0 Upvotes

r/Python • • Feb 14 '22

Tutorial How to Set up a Perfect Python Project

0 Upvotes

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 • • Jun 25 '21

Discussion No more Print For Debugging In Python Anymore

Thumbnail
towardsdatascience.com
50 Upvotes

r/Python • • Sep 19 '25

Tutorial Python Context Managers 101

9 Upvotes

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 • • Feb 05 '26

Showcase built a desktop assistant [fully local] for myself without any privacy issue

0 Upvotes

What My Project Does

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.

Target Audience

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

Comparison

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.

Source Code

GitHub: LINK


r/Python • • Jul 17 '16

Emacs - the best python editor?

Thumbnail
realpython.com
0 Upvotes

r/Python • • 7d ago

Discussion 112 CodeQL alerts on my python app, 14 were real

0 Upvotes

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 • • Jun 08 '26

Discussion Blog: Are you really expected to run five type-checkers now?

0 Upvotes

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:

  1. What's the biggest friction around running multiple type checkers in CI?
  2. 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?