Registry /
serialization / drf-jsonschema-serializer
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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 74.1MB
glibcpy 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.fixUpgrade 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.fixReplace `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.fixIf 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