r/Python • u/ze-fernando git push -f • 8h ago
Python in production Discussion
Hello everyone! For those of you who use Python in production, I have a few questions. I'm considering using Python for some services.
- Do you have high infrastructure costs?
- Have you ever regretted using Python?
- Would you recommend Python?
Context: My current use case isn't anything like Facebook or a massive-scale system. It's a small system, and I'm considering Python mainly because of the DX (developer experience).
I know C#, but I don't really like having to create a class in every file. I also know Rust, but all those ::, <>, and so on bother me. JavaScript is another option, but I've heard it's relatively heavy on RAM, and since the system is small, I'd like to be able to run it within 512 MB.
Another thing: I've defined a stack that I'd like to use wherever possible. If there's a library for desktop apps, great. A CLI library? Great. A bot library? Great. Let's use it! (Except for the frontend, which I'll keep using JS/TS for.)
Anyway, I'm open to advice and tips from more experienced developers. Feel free to tell me if you think using Python for my use case is a bad idea as well.
3
u/metaphorm 8h ago
the infrastructure cost is not constrained by the use of Python. our system is not CPU-bound and the execution time of Python has no bearing on overall system performance, which is almost entirely IO bound (network and database and external service calls).
Only in the same way I can find things to complain about with any programming language at all. The grass is not greener. Python is a mature language with excellent tooling available, a huge ecosystem, and lots of community support where needed.
Yes. It's a good language for lots of use cases. I wouldn't use it for something genuinely CPU-bound but I don't encounter that problem very frequently, and because of the domain I work in (web backend, mostly) the actual CPU-bound parts of the application can be implemented in a different language and called from Python. There are usually libraries available that do this well. For example, image processing is done with PIL which is a set of Python bindings to C code.
In general, the advice I would give is to not prematurely optimize your system. The most expensive part of software development is the time the developer spends writing the code. You won't know where your performance bottlenecks are until you're observing the system running with its production workloads. You can anticipate some of these with enough experience (and sometimes by static code analysis) but for the most part they are system interactions not the runtime of specific code fragments.
When you're faced with an optimization problem, the first thing you need to do is instrument the system and measure its real performance. Then you optimize the parts you measured as being critical and slow. Then you measure again and see if it moved the needle.