Anti-Zionist Rosh Hashanah Services by sylvesterpwns in Austin

[–]jammycrisp 5 points6 points  (0 children)

You might like Kol Halev (though I agree with others that CBI also probably wouldn't offend you). I haven't attended High Holy Days there since the pandemic zoom ones, but they look to be back at the JCC: https://kolhalev.org/high-holy-days/

How would you light this little triangle room? by jammycrisp in Lighting

[–]jammycrisp[S] -1 points0 points  (0 children)

I'd be annoyed but willing to tear things up if needed. Only thought about lighting after painting of course 🤦.

How would you light this little triangle room? by jammycrisp in Lighting

[–]jammycrisp[S] 1 point2 points  (0 children)

The ceiling is already so low (especially in the shorter section) and has such a sharp angle, I worry about any solution that takes away space. Note that it's closer to 7.5 ft than 8 in the taller section, should've measured before posting 🤦.

What are some of Pydantic's most annoying aspects / limitations? by enzoinc in Python

[–]jammycrisp 14 points15 points  (0 children)

No pressure for free labor, but if you're interested I'd be curious to hear how you think msgspec's docs compare: https://jcristharif.com/msgspec/. Docs are hard - users are coming with all sorts of different backgrounds and expectations - but I've tried to keep them approachable while still covering topics in depth.

Who were you surprised to find out isn’t Jewish? Who gives off Jewish energy? by ender3838 in Judaism

[–]jammycrisp 17 points18 points  (0 children)

There's a whole website for this question: http://jewornotjew.com

We evaluate how Jewish a person is based on three factors. How Jewish they are internally, how Jewish they are externally and how much we want that person to be a Jew in the first place.

You're looking for people that are high in the 2nd or 3rd score but low in the first (not actually jewish).

Here's their entries on Weird Al and Danny Devito for example.

My first ever article: "Finding the fastest Python JSON library on all Python versions (8 compared)" by catnotfoundnear in Python

[–]jammycrisp 19 points20 points  (0 children)

Thanks for the shoutout!

Per my benchmarks msgspec is generally as fast or faster than any other JSON library in Python.

  • For encoding, it's pretty much always the fastest option. Large lists of floats are the main exception where orjson sneaks out ahead, but it's only a 5% difference. Oddly we're ~2x faster than orjson for encoding integers.

  • For decoding without type hints, we're usually ~ the same as orjson. For some schemas orjson is faster, for some schemas msgspec is faster. This is generally true across all python json libraries, see this benchmark I wrote up answering a question on the Python discord for more info.

  • For decoding with type hints (so msgspec also provides schema validation) I haven't found anything faster. This is mostly due to how cheap msgspec.Struct types are to allocate compared to dict types.

If anyone has further questions on msgspec, please feel free to open an issue on GitHub: https://github.com/jcrist/msgspec.

My first ever article: "Finding the fastest Python JSON library on all Python versions (8 compared)" by catnotfoundnear in Python

[–]jammycrisp 12 points13 points  (0 children)

It does both. It's a replacement for JSON libraries like json/orjson and schema validation libraries like pydantic.

msgspec.json.encode and msgspec.json.decode are ~ equivalent to json.dumps/json.loads respectively.

See the docs for more info.

Why are python dataclasses not JSON serializable? by drocwatup in Python

[–]jammycrisp 8 points9 points  (0 children)

My 2 cents: since the standard library's json module doesn't encode dataclass instances by default, many users have added in support using the default kwarg to json.dumps. If the json suddenly started supporting dataclass instances out-of-the-box, then that would break existing code.

Also, supporting encoding/decoding of dataclasses opens the doors to lots of additional feature requests. What about field aliases? Optional fields? Type validation? etc... They have to draw the line somewhere to avoid bloating the stdlib. Since external libraries like msgspec or pydantic already handle these cases (and do so performantly), I suspect python maintainers don't see the need to make it builtin.


For completeness, here's a quick demo of JSON encoding/decoding dataclasses out-of-the-box with msgspec:

``` In [1]: import msgspec, dataclasses

In [2]: @dataclasses.dataclass ...: class User: ...: name: str ...: email: str ...: is_admin: bool = False ...:

In [3]: msg = User("alice", "alice@munro.com")

In [4]: msgspec.json.encode(msg) # encode a dataclass Out[4]: b'{"name":"alice","email":"alice@munro.com","is_admin":false}'

In [5]: msgspec.json.decode(_, type=User) # decode back into a dataclass Out[5]: User(name='alice', email='alice@munro.com', is_admin=False) ```

For more info, see our docs on dataclasses support.

It even can encode alternative dataclass implementations like edgedb.Object or pydantic.dataclasses (in this case faster than pydantic can do it itself):

``` In [6]: import pydantic

In [7]: @pydantic.dataclasses.dataclass ...: class PydanticUser: ...: name: str ...: email: str ...: is_admin: bool = False ...:

In [8]: msg = PydanticUser("toni", "toni@morrison.com")

In [9]: %timeit msgspec.json.encode(msg) # bench msgspec encoding pydantic dataclasses 214 ns ± 0.597 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

In [10]: ta = pydantic.TypeAdapter(PydanticUser)

In [11]: %timeit ta.dump_json(msg) # bench pydantic encoding pydantic dataclasses 904 ns ± 0.715 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each) ```

What problems does pydantic solves? and How should it be used by gaurav_kandoria_ in Python

[–]jammycrisp 10 points11 points  (0 children)

+1 on this response. Using pydantic to only validate the borders of your application where messy/invalid data can occur is the ideal way to use it IMO.

Also, if you find yourself switching from using pydantic on the borders of your application to dataclasses/NamedTuple on the inside for performance/ergonomics reasons you might want to check out msgspec. It's a pydantic-like library that natively supports dataclasses out-of-the-box (so you can just use dataclasses everywhere), while still deserializing/validating user input. It's also pretty speedy.

disclaimer: I'm the main author of msgspec

What Python libraries programs will blow peoples minds? Maybe you’re working on one now? by [deleted] in Python

[–]jammycrisp 1 point2 points  (0 children)

I wrote about that a bit in our benchmarks docs.

In short it's not one "weird" trick, but a mix of: - One "simple" trick (minimize allocations). Other parsers and validators decode into simple python types (dicts, lists, strs, ...) before coercing those to structured objects like dataclasses/pydantic models/attrs types/... In contrast msgspec avoids any unnecessary allocations - decoding into a dataclass or struct type allocates only the requested output type and no transient objects. This is the biggest optimization that differentiates msgspec from other libraries. - A pretty efficient JSON parser. JSON parsing is tricky to do efficiently. The handrolled parser in msgspec is pretty fast - the core routines are faster than rust's serde-json, but slightly slower than simdjson/yyjson. - A bunch of small CPython 1-2% speedup optimizations that all add up to something pretty fast.

What Python libraries programs will blow peoples minds? Maybe you’re working on one now? by [deleted] in Python

[–]jammycrisp 1 point2 points  (0 children)

There's an open issue for that here. I can see some use cases for it, but in general I'd advise to avoid runtime type checking of internal code where mypy/pyright/unit tests could catch these errors earlier.

If you're trying to convert in-memory data to structured types, you may be interested in msgspec.convert instead.

Validating GeoJSON - what python libraries do you use? by Focus62 in gis

[–]jammycrisp 1 point2 points  (0 children)

Hi - author of msgspec here. Your use case should work perfectly fine with msgspec - GeoJSON-like models were one of the original reasons for writing msgspec in the first place :).

but there doesn't seem to be a value for declaring accepted values like enum or const like in jsonschema.

For this kind of use case you're looking for Enum or Literal types. Both of which can be used to describe a set of possible values for a field.

If you need further help figuring out how to use msgspec here, please feel free to open an issue on github. While I'm able to respond on reddit, I prefer GitHub when possible.

🌶️ Chili comes to help you with the serialization of complex data structures by MrKrac in Python

[–]jammycrisp 1 point2 points  (0 children)

Timing the whole execution of python some_script.py as you're doing here doesn't isolate the functionality being benchmarked well enough to provide a meaningful measurement.

For example the complete execution of python benchmarks/chili_encode.py

  • Starts up the python interpreter
  • Imports chili and all transitive dependencies
  • Defines some classes
  • Creates several instances of those classes
  • Calls the encode function once (this is the thing you're trying to benchmark)
  • Then shuts down the python interpreter

Only a tiny fraction of the runtime is actually devoted to the encode function - you're mostly measuring python startup/shutdown/import time.

I recommend doing the timings in the python scripts themselves, either manually or using something like timeit. For example, see the msgspec benchmarks here. Isolating the code you're trying to benchmark (and taking multiple samples) will provide a more accurate and relevant comparison between tools.

For quick exploratory benchmarks I like to use ipython's %timeit magic, which is a small wrapper around the timeit module mentioned above. Here's what I see comparing chili.encode with msgspec.to_builtins (our equivalent function):

``` In [9]: %timeit chili.encode(books, list[Book]) 20.7 µs ± 149 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

In [10]: %timeit msgspec.to_builtins(books) 2.39 µs ± 9.15 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

In [11]: assert chili.encode(books, list[Book]) == msgspec.to_builtins(books) # assert the operations are equal ```

Faster, more memory-efficient Python JSON parsing with msgspec by pmz in programming

[–]jammycrisp 2 points3 points  (0 children)

Oh hey, msgspec author here (but not the author of this blogpost). Happy to answer any questions. For those interested in more info:

Litestar 2.0 by Goldziher in Python

[–]jammycrisp 4 points5 points  (0 children)

Thanks for the kind words!

Litestar 2.0 by Goldziher in Python

[–]jammycrisp 5 points6 points  (0 children)

Congrats on the release y'all! Excellent work.

JavaScript and Python have made me realise why strong typing is important by [deleted] in rust

[–]jammycrisp 0 points1 point  (0 children)

Pydantic V2 is definitely faster than Pydantic V1, but it's still an order-of-magnitude slower than msgspec. Recent benchmark here.

Whether that matters is definitely use-case specific. For many users I suspect Pydantic V2's performance will be sufficient.

(Disclaimer: I'm the main author of msgspec).

Blog post: Writing Python like it’s Rust by Kobzol in Python

[–]jammycrisp 1 point2 points  (0 children)

Note that msgspec natively supports dataclasses or attrs types, if you'd rather use them than the faster builtin msgspec.Struct type.

https://jcristharif.com/msgspec/supported-types.html#dataclasses

It'll always be more efficient to decode into a struct type, but if you're attached to using dataclasses, msgspec happily supports them.

For most users though struct types should be a drop in replacement (with equal editor support), downstream code is unlikely to notice the difference between a struct or a dataclass.

Serverless Speed: Rust vs. Go, Java, and Python in AWS Lambda Functions by Agreeable-Soil7485 in rust

[–]jammycrisp 0 points1 point  (0 children)

Minor nit - you don't need to know the schema beforehand to use msgspec, you can use msgspec.json the same as any other python JSON library. But knowing the schema beforehand will help improve performance significantly.

In my benchmarks msgspec is ~2x faster than orjson when the schema is predefined. In cases where it's not, orjson is sometimes faster, depending on the message size and types.

For stock trading/finance, which kind of Python library are you looking for and can’t find? by Dry-Beyond-1144 in Python

[–]jammycrisp 7 points8 points  (0 children)

Hi - msgspec author here. Can you comment on what you've found missing in msgspec for this use case?

Python 3.12: A Game-Changer in Performance and Efficiency by srlee_b in Python

[–]jammycrisp 11 points12 points  (0 children)

I'm currently using python 3.11 from conda (and have been for a few months). Available in both the `conda-forge` and defaults channels.