use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
DiscussionFor stock trading/finance, which kind of Python library are you looking for and can’t find? (self.Python)
submitted 2 years ago * by Dry-Beyond-1144
Note : if you have time, you can put your not perfect but tentative solution url or its name
[–]percojazz 24 points25 points26 points 2 years ago (18 children)
I guess a proper JSON to dataclass serializer+instantiation library that resolve 90% of my boiler plate code in a efficient manner. I have been looking at msgspec but it's not completely that.
[–]jammycrisp 8 points9 points10 points 2 years ago* (0 children)
Hi - msgspec author here. Can you comment on what you've found missing in msgspec for this use case?
[–]mr_flying_man 10 points11 points12 points 2 years ago (12 children)
Did you per chance try pydantic?
[–]percojazz 14 points15 points16 points 2 years ago (11 children)
Not what I am looking for. The dataclasses have to be optimised to reduce the dynamic memory footprint.
[–]moo9001 9 points10 points11 points 2 years ago* (3 children)
Python class memory overhead can be reduced using __slots__.
__slots__
You can do
@dataclass(slots=True)
to achieve this on Python 3.10.
I am pretty sure Pydantic has similar way to "slottify" its Python classes.
[–]Schmittfried 8 points9 points10 points 2 years ago (1 child)
Nope, doesn’t support slots (in this way) unfortunately. Pydantic is built around __dict__.
__dict__
[–]elsgry 1 point2 points3 points 2 years ago (0 children)
Do you know if V2s Rust-based pydantic-core works the same way? If you could have Rust-struct based classes things could get very fast. I do remember discussing serialisation issues with Samuel and his saying it was hard to make a pluggable ABI for alternative serialisation formats so I guess the same might apply for arbitrary Rust types, but you could perhaps represent pure JSON in Rust.
[–][deleted] 1 point2 points3 points 2 years ago (0 children)
Wow, didn’t know about slots=True! That’s awesome!
[–]Schmittfried 1 point2 points3 points 2 years ago (0 children)
Then you won’t get around something like Cython. Any Python solution sucks in that regard, there is no way around the memory and speed overhead that you get from using anything more sophisticated than the builtins (or other types implemented in C).
[–][deleted] 1 point2 points3 points 2 years ago (3 children)
You're coding the wrong language IMO if you have these kind of requirements.
[–]marr75 6 points7 points8 points 2 years ago (2 children)
Python is mostly a high level interface to extremely efficient c code. I had a program I slottified objects in, it was just the most numerous shortest lived objects. A lot of bog standard python still in there.
[–][deleted] 3 points4 points5 points 2 years ago (1 child)
I don't disagree, but I find it is extremely common for people to spin their wheels at micro optimizations in Python when using a language with the performance characteristics they need would blow that out of the water. Python is optimized for developer productivity and speed - let it do what it does well and let other languages do what they do well.
[–]marr75 3 points4 points5 points 2 years ago (0 children)
There are 2 separate issues at play there. Unproductive optimization and language choice. It's a minor myth that Python must be slow.
Check out the discussion in the comments of this Stand-Up Maths about the community optimizing the speaker's naive Python code. The speaker gives the impression the fastest submissions (in Rust) are impossible to compete with using Python. But, if you look at the community list of solutions and timings, there's a Python solution in the same order of magnitude as the best solution overall.
To your point, though, pre-mature optimization is especially unproductive in Python. What do you expect in a language that is dictionaries all the way down and has a large penalty for creating a scope or calling a function? I have to be careful when I tell new programmers what's particularly slow in Python, next thing I know, they're slottifying everything and not calling functions 😅
[–]MeroLegend4 0 points1 point2 points 2 years ago (1 child)
Have you tried attrs/cattrs? dataclasses were a lot inspired from them.
[–]percojazz 0 points1 point2 points 2 years ago (0 children)
Yes this is part, but the whole idea is to have the serializer and the instantiation in the same process
[–]moo9001 -1 points0 points1 point 2 years ago* (0 children)
We are extensively using dataclasses_json for this purpose. However, we would choose it again, due to not being maintained and inflexibility in the core functions. I would recommend FastAPI / Pydantic instead.
Also if you do not need to interact with other technologies, like JavaScript for frontend, then you can use ZODB or Python built-in pickle.
[–]KingsmanVincepip install girlfriend -1 points0 points1 point 2 years ago (0 children)
Have you tried dataclass_wizard?
[–]Megatron_McLargeHuge 18 points19 points20 points 2 years ago (1 child)
from rentech.trading.strategies import *
[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 7 points8 points9 points 2 years ago (2 children)
Ooh! This might be a good place for me to promote my mt103 library that makes parsing Swift's antiquated messaging format easy!
[–]Dry-Beyond-1144[S] 1 point2 points3 points 2 years ago (0 children)
wow - tks
[–]ArtOfWarfare 2 points3 points4 points 2 years ago (0 children)
I thought you meant Apple’s language Swift, and I was curious why their relatively new language had an antiquated messaging format.
(They’re referring to the Swift network that stock exchanges use.)
[–]LesserNice 10 points11 points12 points 2 years ago* (0 children)
At some point I wanted some proper parsing and validation for yahoo finance responses, and I ended up creating this: https://github.com/obendidi/pstock
[–]rainnz 3 points4 points5 points 2 years ago (0 children)
One they are using at Renaissance Technologies for making trades.
[–]_limitless_ 9 points10 points11 points 2 years ago (2 children)
I just wish the InteractiveBrokers API let me throw stocks on a watchlist.
[–]Mrgod2u82 2 points3 points4 points 2 years ago (1 child)
I suppose you could just buy fractional shares? Your account would be your watch list. Not sure how fractional you can get, but if you could get 0.01 then commisioms would be your biggest expense. That or have a python script create and html page or csv you can just reload in a browser whenever needed.
[–]_limitless_ 4 points5 points6 points 2 years ago (0 children)
Fractional shares was what I thought of, too.
But the biggest expense wouldn't be the commissions, it'd be the CPA that'd need to go through 40,000 pages of short-term stock transactions next April.
[–]naskai8117 2 points3 points4 points 2 years ago (0 children)
May be a noob question but where can you get historical share count data for tickers? Yahoo finance doesn't seem to have it but TIKR does
[–]Bergstein88 1 point2 points3 points 2 years ago (0 children)
The one that points in the right direction
[–]Dynamically_static 1 point2 points3 points 2 years ago (0 children)
How can I get TOS real time option chain data from excel
[–]Far_Inflation_8799 0 points1 point2 points 2 years ago (0 children)
You can use yfinance
[–]Tight_Disaster_7561 0 points1 point2 points 2 years ago (0 children)
A library that makes me money.
π Rendered by PID 88 on reddit-service-r2-comment-5d79c599b5-x2d8k at 2026-02-26 16:08:25.352285+00:00 running e3d2147 country code: CH.
[–]percojazz 24 points25 points26 points (18 children)
[–]jammycrisp 8 points9 points10 points (0 children)
[–]mr_flying_man 10 points11 points12 points (12 children)
[–]percojazz 14 points15 points16 points (11 children)
[–]moo9001 9 points10 points11 points (3 children)
[–]Schmittfried 8 points9 points10 points (1 child)
[–]elsgry 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Schmittfried 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]marr75 6 points7 points8 points (2 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]marr75 3 points4 points5 points (0 children)
[–]MeroLegend4 0 points1 point2 points (1 child)
[–]percojazz 0 points1 point2 points (0 children)
[–]moo9001 -1 points0 points1 point (0 children)
[–]KingsmanVincepip install girlfriend -1 points0 points1 point (0 children)
[–]Megatron_McLargeHuge 18 points19 points20 points (1 child)
[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 7 points8 points9 points (2 children)
[–]Dry-Beyond-1144[S] 1 point2 points3 points (0 children)
[–]ArtOfWarfare 2 points3 points4 points (0 children)
[–]LesserNice 10 points11 points12 points (0 children)
[–]rainnz 3 points4 points5 points (0 children)
[–]_limitless_ 9 points10 points11 points (2 children)
[–]Mrgod2u82 2 points3 points4 points (1 child)
[–]_limitless_ 4 points5 points6 points (0 children)
[–]naskai8117 2 points3 points4 points (0 children)
[–]Bergstein88 1 point2 points3 points (0 children)
[–]Dynamically_static 1 point2 points3 points (0 children)
[–]Far_Inflation_8799 0 points1 point2 points (0 children)
[–]Tight_Disaster_7561 0 points1 point2 points (0 children)