Prisma Client Py Versions Save

Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use

v0.13.1

1 month ago

This is a patch release to fix a minor regression with datasource env vars and datasource overriding.

v0.13.0

1 month ago

What's changed

Customisation of client model instance names

Up until now, if you had a schema like this defined:

model OrgMember {
  // ...
}

You would have to access it like this:

from prisma import Prisma

client = Prisma()
member = client.orgmember.find_unique(...)

With this release you can customise the instance name on the client, e.g. orgmember, to whatever you would like! For example:

/// @Python(instance_name: "org_member")
model OrgMember {
  // ...
}

The OrgMember model can now be accessed through the client like so:

client = Prisma()
client.org_member.find_unique(...)

A future release will also add support for changing the default casing implementation used in the client!

Prisma upgrades

The internal Prisma version has been bumped from 5.8.0 to 5.11.0, you can find the release notes for each version below:

Official support for Python 3.12

Up until now Prisma Client Python didn't declare support for Python 3.12 but it will have worked at runtime. The only user facing changes in this release are to the python -m prisma_cleanup script to avoid a deprecation warning.

Minor internal breaking changes

Some minor changes were made to modules that were intended to be private but were not marked with a preceding _.

  • prisma.builder has been moved to prisma._builder
  • The main export from the prisma.builder module, QueryBuilder, has new required constructor arguments

Misc changes

I've also started laying the ground work for usage of both the async client and the sync client at the same time and hope to support this in the next release!

New Contributors

Sponsors

sponsors

v0.12.0

3 months ago

What's Changed

This release bumps the internal Prisma version from 5.4.2 to 5.8.0 bringing major preview improvements to distinct & joins.

This release also ensures we use a consistent enum format on Python 3.11 upwards, see this issue for more details.

Misc changes

  • Minor improvements to docs thanks to @Oreoxmt & @tooruu!

Sponsors

sponsors

v0.11.0

6 months ago

What's Changed

This release bumps the internal Prisma version from 4.15.2 to 5.4.2 bringing major performance improvements.

This release also adds support for retrieving metrics, e.g.

from prisma import Prisma

client = Prisma()

metrics = client.get_metrics()
print(metrics.counters[0])

See the docs for more information.

Misc changes

Sponsors

sponsors

v0.10.0

8 months ago

What's Changed

This release adds support for Pydantic v2 while maintaining backwards compatibility with Pydantic v1.

This should be a completely transparent change for the majority of users with one exception regarding prisma.validate.

Due to this bug we can't use the new TypeAdapter concept in v2 and instead rely on the v1 re-exports, this has the implication that any errors raised by the validator will need to be caught using the v1 ValidationError type instead, e.g.

from pydantic.v1 import ValidationError
import prisma

try:
    prisma.validate(...)
except ValidationError:
    ...

Improved timeouts inputs

All timeout arguments now accept a datetime.timedelta instance as well as the previously accepted int / float types, however support for int / float has been deprecated and will be removed in a future release.

The previous values were used inconsistently, sometimes it meant seconds and sometimes it meant milliseconds. This new structure is more flexible and allows you to specify the time in whatever format you'd like. Thanks @jonathanblade!

from datetime import timedelta
from prisma import Prisma

db = Prisma(
  connect_timeout=timedelta(seconds=20),
)

Misc Changes

Thanks @zspine and @jonathanblade for contributing!

sponsors

v0.9.1

10 months ago

This release pins pydantic to < 2 as v2.0.0 is not yet compatible with Prisma.

Misc Changes

Thanks to @izeye and @Leon0824 for contributing!

Sponsors

sponsors

v0.9.0

10 months ago

What's Changed

Support for Interactive Transactions

This release adds support for interactive transactions! This means you can safely group sets of queries into a single atomic transaction that will be rolled back if any step fails.

Quick example:

from prisma import Prisma

prisma = Prisma()
await prisma.connect()

async with prisma.tx() as transaction:
    user = await transaction.user.update(
        where={'id': from_user_id},
        data={'balance': {'decrement': 50}}
    )
    if user.balance < 0:
        raise ValueError(f'{user.name} does not have enough balance')

    await transaction.user.update(
        where={'id': to_user_id},
        data={'balance': {'increment': 50}}
    )

For more information see the docs.

Support for find_unique_or_raise & find_first_or_raise

This release adds two new client methods, find_unique_or_raise & find_first_or_raise which are the exact same as the respective find_unique & find_first methods but will raise an error if a record could not be found.

This is useful when you know that you should always find a given record as you won't have to explicitly handle the case where it isn't found anymore:

user = await db.user.find_unique_or_raise(
    where={
        'id': '...',
    },
    include={
        'posts': True,
    },
)

Prisma updates

This release bumps the internal Prisma version from v4.11.0 to v4.15.0.

Some of the highlights:

For the full release notes, see the v4.12.0, v4.13.0, v4.14.0 and v4.15.0 release notes.

Miscellaneous Changes

Sponsors

Huge thank you to @isometric & @techied for their continued support!

sponsors

v0.8.2

1 year ago

Prisma updates

This release bumps the internal Prisma version from v4.10.1 to v4.11.0, although there aren't any major changes here for Prisma Client Python users.

The full release notes can be found here.

Bug fIxes

v0.8.1

1 year ago

Support for selecting fields

This release adds support for selecting fields at the database level!

This currently only works for queries using model based access either by defining your own model classes or generating them using partial types.

Quick example:

from prisma.bases import BaseUser

class UserWithName(BaseUser):
  name: str

# this query will only select the `name` field at the database level!
user = await UserWithName.prisma().find_first(
  where={
    'country': 'Scotland',
  },
)
print(user.name)

For a more detailed guide see the docs.

Support for distinct filters

You can now pass in a distinct filter to find_first() and find_many() queries.

For example, the following query will find all Profile records that have a distinct, or unique, city field.

profiles = await db.profiles.find_many(
    distinct=['city'],
)
# [
#  { city: 'Paris' },
#  { city: 'Lyon' },
# ]

You can also filter by distinct combinations, for example the following query will return all records that have a distinct city and country combination.

profiles = await db.profiles.find_many(
    distinct=['city', 'country'],
)
# [
#  { city: 'Paris', country: 'France' },
#  { city: 'Paris', country: 'Denmark' },
#  { city: 'Lyon', country: 'France' },
# ]

CLI support for specifying the generator to use

Thanks to @yukukotani's great work on the CLI you can now ergonomically share the same schema between multiple languages, for example with the following schema:

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

generator node {
  provider = "prisma-client-js"
}

generator python {
  provider = "prisma-client-py"
}

model User {
  id   Int    @id
  name String
}

You can now skip the generation of the Node client with the --generator argument:

prisma generate --generator=python

See the generate documentation for more details.

Bug fixes

Prisma updates

This release bumps the internal Prisma version from v4.8.0 to v4.10.1

For the full release notes, see the v4.9.0 release notes and the v4.10.0 release notes.

Minimum required type checker version

Before this release there were no explicit compatibility requirements for type checkers. From now on we will only support the latest versions of Mypy and Pyright.

In the next release the mypy plugin will be deprecated and later removed entirely. There is a bug in the plugin API in the latest versions of mypy that completely breaks the plugin and seems impossible to fix. See #683 for more information.

Sponsors

Massive thank you to @prisma, @techied, @exponential-hq and @danburonline for their continued support! Thank you to @paudrow for becoming a sponsor!

sponsors

v0.8.0

1 year ago

⚠️ Prisma Schema Breaking Changes

This release contains some changes to the format of the Prisma Schema.

Most of these changes are due to a conceptual shift from allowing implicit behaviour to forcing verboseness to reduce the amount of under the hood magic that Prisma does, thankfully this means that a lot of the changes that you will be required to make should be pretty straightforward and easily fixable by running prisma format which will show you all the places that need changed in your schema.

Changes:

For more details see the Prisma v4.0.0 upgrade path.

⚠️ Internal Raw Query Changes

This release includes an internal restructuring of how raw queries are deserialized. While all these changes should be completely backwards compatible, there may be edge cases that have changed. If you encounter one of these edge cases please open an issue and it will be fixed ASAP.

For some additional context, this restructuring means that most fields will internally be returned as strings until Prisma Client Python deserializes them (previously this was done at the query engine level).

CLI Improvements

This release completely refactors how the Prisma CLI is downloaded and ran. The previous implementation relied on downloading a single pkg binary, this worked but had several limitations which means we now:

  • Support ARM architectures & certain Linux distributions
  • Support running Prisma Studio from the CLI
  • Support generating the JS Client
  • No longer have to maintain a separate implementation from Prisma for detecting the current platform & logic for downloading engines
    • As a user this means that more platforms & architectures will be supported faster!

The new solution is involves directly downloading a Node.js binary (if you don't already have it installed) and directly installing the Prisma ClI through npm. Note that this does not pollute your userspace and does not make Node available to the rest of your system.

This will result in a small size increase (~150MB) in the case where Node is not already installed on your machine, if this matters to you you can install Prisma Client Python with the node extra, e.g. pip install prisma[node], which will install a Node binary to your site-packages that results in the same storage requirements as the previous pkg solution. You can also directly install nodejs-bin yourself. It's also worth noting that this release includes significant (~50%) reduction in the size of the Prisma Engine binaries which makes the default Node binary size increase less impactful.

Prisma Studio

With this release you can now run Prisma Studio from the CLI which makes it incredibly easy to view & edit the data in your database. Simply run the following command

$ prisma studio

Or

$ prisma studio --schema=backend/schema.prisma

Screenshow showcasing Prisma Studio usage

Note that there is also a dark mode available

Support for CockroachDB

This release adds official support for CockroachDB. You could've used CockroachDB previously by setting provider to postgresql but now you can explicitly specify CockroachDB in your Prisma Schema:

datasource db {
  provider = "cockroachdb"
  url      = env("COCKROACHDB_URL")
}

It should be noted that there are a couple of edge cases:

Prisma Updates

TL;DR for improvements made by Prisma that will now be in Prisma Client Python

Full list of changes:

Miscellaneous Changes

Public Roadmap

Going forward we will now use a GitHub Project to track state and relative priority of certain issues. If you'd like to increase the priority of issues that would benefit you please add 👍 reactions.

This is less of a roadmap per se but will hopefully give you some insight into the priority of given issues / features.

Attributions

Thank you to @kfields for helping with raw query deserialization!

Massive thank you to @prisma & @techied for their continued support and @exponential-sponsorship for becoming a sponsor!

sponsors