Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

v0.7.0

Choose a tag to compare

@RobertCraigie RobertCraigie released this 01 Oct 14:53
· 309 commits to main since this release
fb9a821

Breaking Changes

Path resolution for relative SQLite databases fixed

Previously there was a mismatch between the resolution algorithm for relative SQLite paths which could cause the Client and the CLI to point to different databases.

The mismatch is caused by the CLI using the path to the Prisma Schema file as the base path whereas the Client used the current working directory as the base path.

The Client will now use the path to the Prisma Schema file as the base path for all relative SQLite paths, absolute paths are unchanged.

What's Changed

Add support for configuration through the pyproject.toml file

You can now configure Prisma Client Python using an entry in your pyproject.toml file instead of having to set environment variables, e.g.

[tool.prisma]
binary_cache_dir = '.binaries'

It should be noted that you can still use environment variables if you so desire, e.g.

PRISMA_BINARY_CACHE_DIR=".binaries"

This will also be useful as a workaround for #413 until the default behaviour is changed in the next release.

See the documentation for more information.

Fix .env files overriding environment variables

Previously any environment variables present in the .env or prisma/.env file would take precedence over the environment variables set at the system level. This behaviour was not correct as it does not match what the Prisma CLI does. This has now been changed such that any environment variables in the .env file will only be set if there is not an environment variable already present.

Add support for Python 3.11

Python 3.11 is now officially supported and tested!

It should be noted that you may encounter some deprecation warnings from the transitive dependencies we use.

Add support for generating JSON Schema for Bytes types

You can now generate JSON Schemas / OpenAPI Schemas for models that use the Bytes type.

from prisma import Base64
from pydantic import BaseModel

class MyModel(BaseModel):
    image: Base64

print(MyModel.schema_json(indent=2))
{
  "title": "MyModel",
  "type": "object",
  "properties": {
    "image": {
      "title": "Image",
      "type": "string",
      "format": "byte"
    }
  },
  "required": [
    "image"
  ]
}

Add support for using the Base64 type in custom pydantic models

You can now use the Base64 type in your own Pydantic models and benefit from all the advanced type coercion that Pydantic provides! Previously you would have to manually construct the Base64 instances yourself, now Pydantic will do that for you!

from prisma import Base64
from pydantic import BaseModel

class MyModel(BaseModel):
    image: Base64

# pass in a raw base64 encoded string and it will be transformed to a Base64 instance!
model = MyModel.parse_obj({'image': 'SGV5IHRoZXJlIGN1cmlvdXMgbWluZCA6KQ=='})
print(repr(model.image))  # Base64(b'SGV5IHRoZXJlIGN1cmlvdXMgbWluZCA6KQ==')

It should be noted that this assumes that the data you pass is a valid base64 string, it does not do any conversion or validation for you.

Add support for unregistering a client instance

You can now unregister a client instance, this can be very useful for writing tests that interface with Prisma Client Python. However, you shouldn't ever have to use this outside of a testing context as you should only be creating a single Prisma instance for each Python process unless you are supporting multi-tenancy. Thanks @leejayhsu for this!

from prisma.testing import unregister_client

unregister_client()

Access the location of the Prisma Schema file

You can now access the location of the Prisma Schema file used to generate Prisma Client Python.

from prisma import SCHEMA_PATH

print(SCHEMA_PATH)  # Path('/absolute/path/prisma/schema.prisma')

Other Changes

Contributors

Many thanks to @leejayhsu, @lewoudar, @tyteen4a03 and @nesb1 for contributing to this release!

Sponsors

A massive thank you to @prisma and @techied for their continued support! It is incredibly appreciated 💜

I'd also like to thank GitHub themselves for sponsoring me as part of Maintainer Month!

sponsors