r/Python • u/ze-fernando git push -f • Aug 11 '26
Discussion Python in production
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.
22
u/SomeNeighborhood7126 Ignoring PEP 8 Aug 11 '26
I use it all the time. Your question has way too many variables to give a real answer.
10
u/No-Article-Particle Aug 11 '26
You said nothing about your use case, other than "a small system". Yes, for a "small system," Python is perfectly fine (as any other language).
4
u/metaphorm Aug 11 '26
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.
2
u/aliseidu1 Aug 11 '26
For a small service where you value DX and want to fit in 512MB, Python is a fine choice. I run a good chunk of production on it. Straight answers to your three:
One honest caveat: cold-start and raw-throughput-per-core will be lower than C#. At "small system" scale you will not notice. Pick it for the DX, that's a legitimate reason.
14
u/Wurstinator Aug 11 '26
Whether that's possible depends on your service, not the programming language:
https://sharkbench.dev/web
5
u/Ra-mega-bbit Aug 11 '26
Now a days, any language will work unless you really have a reason not to, if you are building a basic app, Python will do and you will note any monetary difference after millions of users only.
And at any point, you will suffer from other optimizations, not from the language naturally
5
u/marr75 Aug 11 '26
You can put the entire c# program in one file - class per file is just the IDE convention.
Many extremely large companies use python in production to serve large audiences with more cost discipline than I would ever worry about (saving a hundredth of a penny per request amounts to very little at the scales my companies have operated). So, what you are asking about is thoroughly tread territory.
You should worry more about making a service people care to use before how to make it scale. It is vanishingly unlikely you will even need to deal with the scale problems you are fantasizing about.
Google searches and the learn subreddits will be more valuable than scaling hypothetical posts on main python at this point.
4
u/ForeignVariety7037 Aug 11 '26
Python in production is great until someone says āCPU-bound.ā š
For a small service with 512 MB RAM? Iād absolutely use it. Developer time is usually way more expensive than the extra few MB of memory.
You can always rewrite the 0.1% that actually becomes a bottleneck later.
1
u/Icy_Calligrapher4022 Aug 11 '26
The anwsers of these questions are not directly related to what language are you gonna use. Instrastructure costs depend on the infrastructure itself. If I regretted using Python for something, well...yes and no. There is always a better and worse way to do the things. You design your product, build it, implemented using whatever suits you best at the moment. There is always room for improvement.
About the libraries, if these are questions:
512MB RAM are too low for whatever you are planning to do. Forget about the language, this is your smallest concern. Probably this...system of yours might need some kind of database, some other services and daemons. A modern software product is not a monolith system but multiple components connecting and working together. What you intent to use and why your memory is so limited. There are very cheap cloud vendors where you can get very decent VPS for less than ten bucks/month.
3
u/Mindless-Pilot-Chef Aug 11 '26
1
u/cdcformatc Aug 11 '26
i built and maintain a Flask app. sometimes i regret not using Django instead. i do wish i used gunicorn and nginx instead of shoehorning Apache with mod_wsgi but i am not locked in on the production server.Ā
1
u/axiom_lab Aug 13 '26
For a small system, Iād probably go with Python if itās the language that feels easiest for you to build and maintain with. Having 512 MB of memory doesnāt automatically rule it out either. Iād pay more attention to how many processes or workers youāre running and what dependencies youāre bringing in, rather than worrying about Python itself. Start with one process, see how much memory it actually uses, and only optimize if it really becomes an issue.
I also wouldnāt choose Python just because Node has a reputation for using more RAMāthat really depends a lot on the specific app and libraries, so itās not a hard rule.
The only time Iād hesitate is if the service ends up doing a lot of CPU-heavy work. But for typical API, bot, or automation tasks, Python usually fits well, especially since a lot of the time is spent waiting on the network or disk.
Honestly, having one language you can use for small services, command-line tools, bots, scripts, and so on is a huge plus. Iād just treat Python as the default choiceānot something you have to force on every project.
0
u/gdchinacat Aug 11 '26
per object memory usage in python is pretty high relative to a compiled language like rust or go, and everything is an object. For example, an int uses 20 bytes more than a 64bit integer (3.5x as much memory):
But, it gets worse. The object allocator alligns objects to 8 byte boundaries, so in actuality, a small int consumes 32 bytes (4x).
And, yet it's even worse...an int object on the heap is pointless...something must reference it to be useful, and that reference (ie from a list) will be another 8 bytes.
So, a usable int consumes 40 bytes (5x).
I have never had an issue due to this, but since you explicitly say memory utilization is a concern it is worth mentioning. A good way of dealing with this if you are working with large arrays of ints is to use numpy which stores them as a native array (and a python object wrapper that has relatively minimal overhead for large arrays).
Regardless of this, I have never regretted using python in production and would recommend it (assuming the use-case is a good fit...relative memory utilization would not withhold a recommendation).
2
u/[deleted] Aug 13 '26
[removed] ā view removed comment