Registry / serialization / drf-jsonschema-serializer

drf-jsonschema-serializer

JSON →
library3.0.0pypypiunverified

drf-jsonschema-serializer provides automatic JSON Schema generation for Django REST Framework serializers. It allows developers to define DRF serializers as usual and then easily convert them into JSON Schema Draft 2020-12, OpenAPI 3.0.x compatible schemas. The current version is 3.0.0, with releases typically tied to major Django/DRF version compatibility.

pip install drf-jsonschema-serializer
INSTALL
IMPORT
SIG · DRF-JSONSCHEMA-SER
D
drf-jsonschema-serializer
serializationpythonv3.0.0
Install
4.6s avg
Import
—
Disk
74MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 74.1MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 4.6s · import 0.000s · 74MB
74MB installed
● package 74MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSONSchemaSerializer
✓ from drf_jsonschema_serializer import JSONSchemaSerializer
✗ from drf_jsonschema_serializer import JSONSchemaSerializer

This example demonstrates how to define a standard Django REST Framework serializer and then use `drf-jsonschema-serializer` to automatically generate its corresponding JSON Schema. The generated schema can be used for API documentation, client-side validation, or other schema-driven processes.

from rest_framework import serializers from drf_jsonschema_serializer import JSONSchemaSerializer class MyInputSerializer(serializers.Serializer): name = serializers.CharField(max_length=100, help_text="The name of the item") quantity = serializers.IntegerField(min_value=1, help_text="The quantity of the item") is_active = serializers.BooleanField(default=True) # Instantiate the JSONSchemaSerializer with your DRF serializer schema_generator = JSONSchemaSerializer(MyInputSerializer()) # Generate the JSON Schema json_schema = schema_generator.data print(json_schema) # Example expected output (truncated): # { # 'type': 'object', # 'properties': { # 'name': {'type': 'string', 'maxLength': 100, 'description': 'The name of the item'}, # 'quantity': {'type': 'integer', 'minimum': 1, 'description': 'The quantity of the item'}, # 'is_active': {'type': 'boolean', 'default': True} # }, # 'required': ['name', 'quantity'] # }
Debug
Known issues
breakingVersion 3.0.0 drops support for Python < 3.10, Django < 3.2, and Django REST Framework < 3.12. Ensure your environment meets these minimum requirements before upgrading.
fix
Upgrade Python to 3.10+, Django to 3.2+, and DRF to 3.12+ before installing or upgrading to drf-jsonschema-serializer v3.x.
affects: 3.0.0 and higher
breakingThe `JSONSchemaField` class was removed in version 3.0.0. If you were using it for dict or list fields within your DRF serializers, you must migrate to `JSONSchemaDictField` or `JSONSchemaListField` respectively.
fix
Replace `JSONSchemaField` with `JSONSchemaDictField` for dictionary-like schemas and `JSONSchemaListField` for list-like schemas. Update imports to `from drf_jsonschema_serializer.fields import JSONSchemaDictField, JSONSchemaListField`.
affects: 3.0.0 and higher
deprecatedThe `JSONSchemaView` for serving schema endpoints was removed in v2.0.0. While this predates v3.0.0, users migrating from very old versions might encounter issues. The library now focuses purely on schema generation.
fix
If you require serving JSON Schemas via an API endpoint, consider using `drf-spectacular` for OpenAPI schema generation, or implement a custom view that utilizes `drf-jsonschema-serializer` directly to generate and serve the schema.
affects: 2.0.0 and higher
Upgrade
Version history
3.0.0latest on PyPI · released Jun 26, 2024
Audit
Dependencies
DjangorequiredRequired for Django projects and DRF integration (>=3.2)
djangorestframeworkrequiredCore dependency for serializer introspection (>=3.12)
jsonschemarequiredUsed for schema validation and generation (>=4.0)
drf-spectacularoptionalOptional integration for OpenAPI schema generation, if desired
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
drf-jsonschema-serializer — pip install drf-jsonschema-serializer · libregistry