pg_serializer: Very fast JSON serializer using Django and PostgreSQL
Overview
Django REST framework is a powerful and flexible toolkit for building Web APIs.
Django Rest Framework is a great framework for building REST APIs on top of Django and
it fits 99% of use cases.
However, JSON serialization is done in Python and it can be very slow for
some list endpoints that return a lot of records.
pg_serializer aims to soften this 1% issue by providing a way to do JSON serialization
inside your PostgreSQL database. Indeed, PostgreSQL has a built-in support for JSON
since version 9.2, and it is far more faster than Python's one.
Installation
pip install pg-serializer
Basic usage
pg_serializer features an automatic ModelSerializer like DRF.
from django.contrib.auth.models import User
import pg_serializer
class UserSerializer(pg_serializer.ModelSerializer):
class Meta:
model = User
fields = (
"id",
"username",
"email",
"first_name",
"last_name",
"is_staff",
"date_joined",
)
json_str = UserSerializer(User.objects.all()).json
It also has preliminary support for ForeignKey relation using the Django __ separator.
import pg_serializer
class OrderSerializer(pg_serializer.ModelSerializer):
buyer = pg_serializer.StringField(source="buyer__username")
class Meta:
model = Order
fields = (
"transaction_id",
"transaction_time",
"buyer",
"is_gift",
"shipping_date",
"additional_data",
)
json_str = OrderSerializer(Order.objects.all()).json
Full examples are available inside tests/models.py and tests/serializers.py.
Disclaimer ⚠️
pg_serializeris not designed to replace DRF serializers, only to speed up some endpoints when performance is becoming an issuepg_serializeris still in alpha development: bugs can occur and it doesn't support all Django fields and relations
Roadmap
- reinforce the test suite
- implement (and document) custom datetime and decimal formatting
- document how to create custom serializer fields
- full support for ArrayField and JSONField
- complex queryset operations (GROUP BY, ...) support
Metadata
Release files for pg-serializer 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pg_serializer-0.1.3.tar.gz | 7.6 kB | Without provenance | Details for pg_serializer-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pg_serializer-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for pg_serializer-0.1.3-py3-none-any.whl |
Total release size: 16.0 kB
Release files / pg_serializer-0.1.3.tar.gz
| Download URL | pg_serializer-0.1.3.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c8e7ce593755ac73e221d2b3cee9982beefed06fc7416761eb85e9e094a540c
|
|
BLAKE2b-256 checksum How to use checksums |
6674eb0ba0266c07681f9a1058090995e4455800cf6b30ba0d22d64975346117
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/3.9.0 Darwin/19.6.0
|
Release files / pg_serializer-0.1.3-py3-none-any.whl
| Download URL | pg_serializer-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8d255956918fb763a50d50863af2a06129109a56a29c86854d1c1a07b987754
|
|
BLAKE2b-256 checksum How to use checksums |
bac8f7bd786c6682fa510cd27faafb1e71b7a6ecb4f0513605f2380f21c9e8cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/3.9.0 Darwin/19.6.0
|
Security for pg-serializer 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.