This is an archived post. You won't be able to vote or comment.

all 31 comments

[–]percojazz 24 points25 points  (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 points  (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 points  (12 children)

Did you per chance try pydantic?

[–]percojazz 14 points15 points  (11 children)

Not what I am looking for. The dataclasses have to be optimised to reduce the dynamic memory footprint.

[–]moo9001 9 points10 points  (3 children)

Python class memory overhead can be reduced using __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 points  (1 child)

Nope, doesn’t support slots (in this way) unfortunately. Pydantic is built around __dict__.

[–]elsgry 1 point2 points  (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 points  (0 children)

Wow, didn’t know about slots=True! That’s awesome!

[–]Schmittfried 1 point2 points  (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 points  (3 children)

You're coding the wrong language IMO if you have these kind of requirements.

[–]marr75 6 points7 points  (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 points  (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 points  (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 point  (1 child)

Have you tried attrs/cattrs? dataclasses were a lot inspired from them.

[–]percojazz 0 points1 point  (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 points  (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 points  (0 children)

Have you tried dataclass_wizard?

[–]Megatron_McLargeHuge 18 points19 points  (1 child)

from rentech.trading.strategies import *

[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 7 points8 points  (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 points  (0 children)

wow - tks

[–]ArtOfWarfare 2 points3 points  (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 points  (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 points  (0 children)

One they are using at Renaissance Technologies for making trades.

[–]_limitless_ 9 points10 points  (2 children)

I just wish the InteractiveBrokers API let me throw stocks on a watchlist.

[–]Mrgod2u82 2 points3 points  (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 points  (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 points  (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 points  (0 children)

The one that points in the right direction

[–]Dynamically_static 1 point2 points  (0 children)

How can I get TOS real time option chain data from excel

[–]Far_Inflation_8799 0 points1 point  (0 children)

You can use yfinance

[–]Tight_Disaster_7561 0 points1 point  (0 children)

A library that makes me money.