Releases: RobertCraigie/prisma-client-py
v0.13.1
v0.13.0
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 toprisma._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!
- fix(node): bump minimum node version to v16
- fix(generator): remove use of deprecated pydantic methods
- fix(types): remove definition of StrEnum as Enum
- fix(requirements): set minimum pydantic version to 1.10.0
New Contributors
Sponsors
v0.12.0
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
Sponsors
v0.11.0
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
v0.10.0
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
- docs: typos
- feat(client): add support for using model queries within transactions
- feat(client): add is_registered() method
Thanks @zspine and @jonathanblade for contributing!
v0.9.1
This release pins pydantic
to < 2
as v2.0.0
is not yet compatible with Prisma.
Misc Changes
- fix(client): ensure engine protocol is properly set
- docs: add missing code block close tag
- docs: polishes & typos
Thanks to @izeye and @Leon0824 for contributing!
Sponsors
v0.9.0
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:
- Introspection warnings for unsupported database features
- Support for passing custom arguments to
prisma db seed
For the full release notes, see the v4.12.0, v4.13.0, v4.14.0 and v4.15.0 release notes.
Miscellaneous Changes
- Bumped minimum required
typing-extensions
version from3.7
to4.0.1
- Added support for the
--generator
option toprisma py generate
as well - Improved internal testing for the synchronous client
- Improved error message for missing engine binary
- Improved error message for usage of unsupported composite types
Sponsors
Huge thank you to @isometric & @techied for their continued support!
v0.8.2
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
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
- Multi-schema support for SQL Server (Preview)
- Improved CLI support for connection proxies
- Improved introspection support for unsupported features
- Smaller engine size in the CLI
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!
v0.8.0
⚠️ 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:
- Explicit unique constraints for 1:1 relations
- Removed support for usage of references on implicit m:n relations
- Enforcing uniqueness of referenced fields in the references argument in 1:1 and 1:m relations for MySQL
- Removal of the
sqlite://
URL prefix, you should now usefile://
instead - Improved grammar for string literals
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
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:
- BigInt ID fields cannot be atomically updated
- BigInt & Int fields cannot be atomically divided
- Array push operation is not supported
Prisma Updates
TL;DR for improvements made by Prisma that will now be in Prisma Client Python
- [3.14.0] PostgreSQL extended indexes support (now generally available)
- [4.0.0] Defaults for scalar lists
- [4.3.0] Prisma CLI exit code fixes
- [4.5.0] PostgreSQL extension management
- [4.7.0] Prisma Schema relationMode is now generally available
- [4.7.0] Query across multiple database schemas in PostgreSQL
- [4.8.0] Decreased the size of the Query Engine binary ~50%
- [4.8.0] Improved support for OpenSSL 3.x
Full list of changes:
- https://github.com/prisma/prisma/releases/tag/3.14.0
- https://github.com/prisma/prisma/releases/tag/3.15.0
- https://github.com/prisma/prisma/releases/tag/3.15.1
- https://github.com/prisma/prisma/releases/tag/3.15.2
- https://github.com/prisma/prisma/releases/tag/4.0.0
- https://github.com/prisma/prisma/releases/tag/4.1.0
- https://github.com/prisma/prisma/releases/tag/4.1.1
- https://github.com/prisma/prisma/releases/tag/4.2.0
- https://github.com/prisma/prisma/releases/tag/4.2.1
- https://github.com/prisma/prisma/releases/tag/4.3.0
- https://github.com/prisma/prisma/releases/tag/4.3.1
- https://github.com/prisma/prisma/releases/tag/4.4.0
- https://github.com/prisma/prisma/releases/tag/4.5.0
- https://github.com/prisma/prisma/releases/tag/4.6.0
- https://github.com/prisma/prisma/releases/tag/4.7.0
- https://github.com/prisma/prisma/releases/tag/4.7.1
- https://github.com/prisma/prisma/releases/tag/4.8.0
Miscellaneous Changes
- Added tests for MariaDB
- Add validation to ensure model names do not clash with reserved keywords
- Removed dev dependencies from the package distribution
- Fixed incorrect type references under certain conditions for partial models
- Added tests to ensure unsupported features for a given database do not pass type checks
- Fixed docs typo - thanks @HigherOrderLogic!
- Moved binaries outside of
/tmp
by default
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!