News for hackers. Stuff that matters.

probablyrobert

Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @02:03PM (#30419384)
Yeah, sharing the same database between two backends would not be a good idea. That said you do not have to use the TypeScript client at the same time as the Python client, they are independent of each other.
Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @01:58PM (#30419337)
Yes I am using the same approach however I am working on using native FFI bindings which is what the TypeScript client is using now.

https://github.com/RobertCraigie/prisma-client-py/pull/165

Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @01:39PM (#30419124)
There is actually an escape hatch you can use, although it is a bit clunky:

    ```py
    from typing import TYPE_CHECKING

    if TYPE_CHECKING:
        Foo = "expression that mypy can understand"
    else:
        Foo = "dynamic expression"
    ```
Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @01:11PM (#30418806)
Thank you! I hope so too, it would be incredibly helpful.
Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @12:37PM (#30418395)
Yes it is rather unfortunate, Python's typing system doesn't support dynamically creating types like you can in TypeScript :/
Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @12:34PM (#30418361)
Yes it is similar to SQLModel however as SQLModel is based off of SQLAlchemy, the query API is not typed. That is the difference.
Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @12:27PM (#30418282)
Yes it is fully typed because of TypedDicts, https://docs.python.org/3/library/typing.html#typing.TypedDi...

SQLAlchemy on the other hand provides very little (if any) type hints for their query API.

Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @12:26PM (#30418265)
You are correct, we use code generation to define the query API types.
Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @12:25PM (#30418253)
Thanks for the feedback, I will add that.

> Prisma Python

I originally decided to go with Prisma Client Python however I found this to be too verbose and have recently used Prisma Python. I do need to decide on one and stick with that. Thanks for pointing that out

Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @12:07PM (#30418041)
Thanks :)

Yeah that is understandable, it is being successfully used in production but it is safer to use a more stable ORM for mission critical products.

If you don't want to have to duplicate your model definitions you could write a custom Prisma Generator to generate models for a different Python ORM.

https://prisma-client-py.readthedocs.io/en/stable/reference/...

Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @12:03PM (#30417991)
ORM stands for Object Relational Mapper and is essentially a wrapper over raw SQL queries to provide an easier to use interface.
Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @11:47AM (#30417827)
Because Prisma Python currently interfaces with the Rust engine over HTTP (I am looking into changing this) and the Rust engines can be found here:

https://github.com/prisma/prisma-engines

Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @11:35AM (#30417687)
I haven't written benchmarks yet but it is something I am working on. The reason that performance is mentioned in the README is that I haven't spent time on improving it yet.

The biggest blockers in terms of performance are:

- Communication with the internal Rust engine is performed over HTTP instead of FFI.

- You cannot select a subset of fields (every scalar field in a model is selected)

- You cannot skip pydantic validation which while fast is unnecessary in some cases

With that said Prisma Python should be reasonably fast but I would expect it to be on the lower end of the spectrum compared to other Python ORMs. I have ran some load tests locally and creating 500,000 records took about 90 seconds.

Re:Show HN: Prisma Python – A fully typed ORM for Python on Monday February 21, 2022 @11:20AM (#30417512)
Good point, I'll update it, thanks!

Show HN: Prisma Python – A fully typed ORM for Python

https://github.com/RobertCraigie/prisma-client-py

I created this ORM to fill a gap in the Python ecosystem. Due to the nature of typing in Python there are no other Python ORMs that can provide correct type hints. Prisma Python manages to work around this by auto-generating python types.Aside from static type checking, providing type hints means that you will get autocomplete suggestions for you which for me is the killer feature for this ORM...

( Read More... | 87 comments | 130 points | on HN )
Full disclosure, I am the creator of this project.

Happy to answer any questions!

Re:Type safe ORM for Python – Prisma Client on Monday October 25, 2021 @01:38PM (#28990731)
Full disclosure - I am also the creator of this package.

Happy to answer any questions!