1
4
submitted 1 week ago by marmelab@lemmy.ml to c/python@lemmy.ml

So I recently inherited a legacy application that was a nightmare to maintain (tooling was clearly lacking and the codebase was pretty outdated). I quickly realized that if I ever wanted to actually enjoy working on it, I would have to give it a proper overhaul.

These are the 5 changes that had some of the biggest impact IMO:

  1. uv: Being new to the Python ecosystem, I didn’t want to figure out pip vs poetry vs pyenv vs virtualenv, so I just used uv and let it handle all of that. One Rust-based tool that installs and pins Python versions, manages the venv automatically and locks deps in a uv.lock for reproducible builds. Installs are also a lot faster, which makes CI a lot less painful.

  2. Ruff: Coming from JS, I really missed eslint --fix for automatically fixing linting issues and format code on save. Ruff brought that experience back. I know that there are plenty of linters and formatters in the Python ecosystem, but this one really stands out for me. Since it’s built in Rust, it’s super fast.

  3. Dependabot: Instead of remembering to update dependencies every few months, I enabled Dependabot. It automatically opens PRs when updates are available and then CI tells me whether they’re safe to merge. It takes only a couple of minutes to set up but saves a lot of maintenance.

  4. Pylance: Without it, VS Code gives generic completions and never warns you about passing the wrong type until runtime. Pylance provides proper type-aware autocompletion, jump-to-definition (even in third-party libraries), inline documentation, and real-time type checking. I personally keep it on "basic" mode for legacy codebases, since "strict" surfaced hundreds of errors (thank you, but no thank you lol).

  5. Pydantic: Pydantic is basically Python’s Zod: you declare a model, pass your data in and get either a validated typed object or a ValidationError naming the exact field at fault. It really helped me keep the codebase clean, with one place defining the shape of the data instead of raw dicts floating around. I use it wherever data comes from outside, like API payloads, forms, and env vars with pydantic-settings, which fails at startup instead of mid-request.

None of these tools changed the application itself. But together they made working on it a lot less frustrating.

2
6
submitted 3 months ago by Zoomba669@lemmy.world to c/python@lemmy.ml

I only know HTML & CSS.

Is is worth it to learn Python?

Is Python a competence inside a package like knowing Excel well, or are there Python only jobs?

3
5
Python 3.14.5 is out! (blog.python.org)
submitted 3 months ago by cypherpunks@lemmy.ml to c/python@lemmy.ml
4
10
Django 6.0 released (www.djangoproject.com)
submitted 8 months ago* (last edited 8 months ago) by cypherpunks@lemmy.ml to c/python@lemmy.ml
5
11
submitted 10 months ago by cypherpunks@lemmy.ml to c/python@lemmy.ml
6
4
submitted 10 months ago by monica_b1998@lemmy.world to c/python@lemmy.ml
7
6
submitted 1 year ago by vi21@lemmy.ml to c/python@lemmy.ml

The default approach involves using TestClient. However, I found that mocking the database, background tasks, etc., is overkill. Do you have any suggestions?

8
4
submitted 2 years ago by daco@lemm.ee to c/python@lemmy.ml

cross-posted from: https://lemm.ee/post/48031022

Hi,

I wanted to use d2 in an environment where I could only install python and npm packages.

Given that, and that I could not find any other solution, I made d2-python-wrapper, a small python wrapper that bundles the d2 binaries.

Now you can use d2 from python like this:

from d2_python import D2

d2 = D2()

# Simple diagram
with open("test.d2", "w") as f:
    f.write("x -> y")

# Default SVG output
d2.render("test.d2", "output.svg")

# PDF output with specific theme
d2.render("test.d2", "output.pdf", format="pdf", theme="1")

The class just wraps the bin, so it works and supports the same as the bin. There is a GitHub Action that gets the bins for each platform (mac, win, linux) from the releases in this repo and publishes it to pip.

You can install this using

pip install d2-python-wrapper

Here is a short post with more context.

Just in case It's useful for anyone. 😁

9
1
submitted 2 years ago by DevCuber@sh.itjust.works to c/python@lemmy.ml

cross-posted from: https://sh.itjust.works/post/27097438

I store my programs in a cryptomator vault which uses a fuse virtual drive (The default on Linux), but when trying to update pip inside a venv I get an error, then any subsequent use of pip also throws an error and {path_to_venv}/lib/python3.12/site-packages/pip/ becomes empty.

I imagine this is an issue that would happen in any FUSE drive although I don't know how to test that.

Here are the logs

  • OS : Fedora 40
  • pip version: 23.3.2 updating to 24.2
  • python version: 3.12.7

I already made a bug report on the github

Does anyone know a temporary workaround for this ?

10
4
submitted 2 years ago by cypherpunks@lemmy.ml to c/python@lemmy.ml

cross-posted from: https://lemmy.ml/post/21461907

So, this uses a macro, but if you're thinking anything is possible with a macro, it's actually not in Rust. The input does still need to parse as valid Rust tokens.

Which means the authors asked themselves at some point: Is the Rust syntax a superset of the Python syntax?
And well, it's not. In particular, some Python keywords will just be tokenized as an identifier (like a variable name).

But it is close enough that the authors decided against requiring a massive string to be passed in, which does amuse me. 🙃

11
4

cross-posted from: https://programming.dev/post/17866168

Hi,

I use gunicorn in my venv

I have quite few venv that run gunicorn.

I would like to reuse gunicorn for other venv

I launch my web application like this

#PWD = venv dir
source ./bin/activate
gunicorn A_WebApp:app
#A_WebApp is my python file A_WebApp.py

I supposes that gunicorn is a shell program ? if yes I should use $PATH ?
or gunicorn is a Python program only ? and then what I should do to use gunicorn in another venv ?

Thanks.

12
10
submitted 2 years ago by Zara@lemmy.ml to c/python@lemmy.ml

Hi,

I'm looking for a software similar to ZoneMinder
https://lemmy.ml/post/18530232

But it seem that ZoneMinder become slowly outdated, php etc..

I've found a couples of alternatives ( hard choice as the limitations of use are often buried deep )

It seem that openCV is really famous for AI Computer vision, So I would be surprise if there were no Python program to manage cameras like a ZoneMinder !?

Do you know any ?

Thanks.

13
13
submitted 2 years ago by martinn@programming.dev to c/python@lemmy.ml

cross-posted from: https://programming.dev/post/13395352

Would love to hear any suggestions, feedback or comments.

14
5
submitted 2 years ago by MichelDesmoulin@lemmy.ml to c/python@lemmy.ml
15
17
submitted 2 years ago by MichelDesmoulin@lemmy.ml to c/python@lemmy.ml
16
2
submitted 2 years ago by ylai@lemmy.ml to c/python@lemmy.ml
17
13
submitted 2 years ago by ylai@lemmy.ml to c/python@lemmy.ml
18
9
submitted 2 years ago by ylai@lemmy.ml to c/python@lemmy.ml
19
4
submitted 2 years ago by slyuser@lemmy.ml to c/python@lemmy.ml

Unleash Your Python Potential with Python IDLE: The Ultimate Beginner's Guide! From Installation Hacks to Secret Debugging Tricks, Master Python IDLE in Minutes! 💻🚀 #Python #Programming #BeginnerGuide

20
6
submitted 2 years ago* (last edited 2 years ago) by Communist@lemmy.ml to c/python@lemmy.ml

I'm just trying to control my smartlights with a script, it seems to be having a lot of problems, I really don't know what I'm doing, i'd appreciate any help I can get

Once I have a script that can individually turn lights on/off i can edit the rest myself, I just can't get the base functionality working.

21
7
submitted 2 years ago by bluestarshield@lemmy.ml to c/python@lemmy.ml

Hey, I've been looking to learn Python for a while, tried as a kid but got bored before I did anything. I was wondering if anyone knew of any good Python self-study workbooks? The ones with exercises in addition to theory. I'm using Mint, in case that brings up any IDE issues.

22
2
submitted 2 years ago by slyuser@lemmy.ml to c/python@lemmy.ml

Developed a script to perform mm to inches conversions, which was conveniently transformed into a web app using Streamlit.

23
19
submitted 2 years ago by cypherpunks@lemmy.ml to c/python@lemmy.ml
24
17
Python 3.13 gets a JIT (tonybaloney.github.io)
submitted 2 years ago by ylai@lemmy.ml to c/python@lemmy.ml
25
2
submitted 2 years ago by cypherpunks@lemmy.ml to c/python@lemmy.ml
view more: next ›

Python

3640 readers
3 users here now

News and discussions about the programming language Python


founded 7 years ago
MODERATORS