{"id":16417486,"url":"https://github.com/Mng-dev-ai/drf-turbo","last_synced_at":"2025-10-26T20:30:38.876Z","repository":{"id":39640934,"uuid":"426664250","full_name":"Mng-dev-ai/drf-turbo","owner":"Mng-dev-ai","description":"An alternative serializer implementation for REST framework written in cython built for speed.","archived":false,"fork":false,"pushed_at":"2023-10-11T01:44:53.000Z","size":630,"stargazers_count":84,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-03T07:20:23.137Z","etag":null,"topics":["cython","django","django-rest-framework","performance","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mng-dev-ai.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-10T14:59:45.000Z","updated_at":"2024-10-23T05:34:42.000Z","dependencies_parsed_at":"2024-10-11T07:12:07.810Z","dependency_job_id":"117e6470-826a-43c9-bb51-ac2a3b0686e4","html_url":"https://github.com/Mng-dev-ai/drf-turbo","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":0.3076923076923077,"last_synced_commit":"ea9a4a4dc324c0b22d33962b79121e13197274c2"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mng-dev-ai%2Fdrf-turbo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mng-dev-ai%2Fdrf-turbo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mng-dev-ai%2Fdrf-turbo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mng-dev-ai%2Fdrf-turbo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mng-dev-ai","download_url":"https://codeload.github.com/Mng-dev-ai/drf-turbo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238394323,"owners_count":19464583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cython","django","django-rest-framework","performance","python"],"created_at":"2024-10-11T07:11:32.267Z","updated_at":"2025-10-26T20:30:38.419Z","avatar_url":"https://github.com/Mng-dev-ai.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"=========\ndrf-turbo\n=========\n\n\n.. image:: https://img.shields.io/pypi/v/drf-turbo.svg\n        :target: https://pypi.python.org/pypi/drf-turbo\n        :alt: Version\n\n.. image:: https://readthedocs.org/projects/drf-turbo/badge/?version=latest\n        :target: https://drf-turbo.readthedocs.io/en/latest/?version=latest\n        :alt: Documentation Status\n\n.. image:: https://static.pepy.tech/personalized-badge/drf-turbo?period=total\u0026units=international_system\u0026left_color=black\u0026right_color=green\u0026left_text=Downloads\n        :target: https://pepy.tech/project/drf-turbo/\n        :alt: Downloads\n\n\nOverview\n------------\ndrf-turbo is a drop-in serializer for Django REST Framework (DRF). drf-turbo serializers run around 7.75 times faster\nthan what what you get from DRF's packaged serializer.\n\n\nRequirements\n------------\n\n* Django\n\n* Django REST Framework\n\n* pytz\n\n* forbiddenfruit\n\n* pyyaml(OpenAPI)\n\n* uritemplate(OpenAPI)\n\n* djangorestframework-simplejwt(OpenAPI)\n\n\nInstallation\n------------\n\n.. code-block:: console\n\n    $ pip install drf-turbo\n\nTo install Cython on MacOS `via Brew \u003chttps://formulae.brew.sh/formula/cython\u003e`_:\n\n.. code-block:: console\n\n    $ brew install cython\n\nPerformance\n-----------\n`drf-turbo` serialization, deserialization and validation performance averages 86% faster than DRF's standard serializer.\n\nFor more details, visit the `benchmarks section \u003chttps://drf-turbo.readthedocs.io/en/latest/performance.html\u003e`_ of the docs.\n\nDocumentation \u0026 Support\n-----------------------\nDocumentation for the project is available at https://drf-turbo.readthedocs.io.\n\nFor questions and support, use github issues\n\nExamples\n========\n\nDeclaring Serializers\n---------------------\n.. code-block:: python\n\n   from datetime import datetime\n   from django.utils.timezone import now\n   import drf_turbo as dt\n\n    class User:\n        def __init__(self, username, email,created=None):\n            self.username = username\n            self.email = email\n            self.created = created or datetime.now()\n\n    user = User(username='test' , email='test@example.com')\n\n\n\n    class UserSerializer(dt.Serializer):\n        username = dt.StrField(max_length=50)\n        email = dt.EmailField()\n        created = dt.DateTimeField()\n\n\nSerializing objects\n-------------------\n\n.. code-block:: python\n\n\n   serializer = UserSerializer(user)\n   serializer.data\n\n    # {'username': 'test', 'email': 'test@example.com', 'created': '2021-11-04T22:49:01.981127Z'}\n\n\nDeserializing objects\n---------------------\n\n.. code-block:: python\n\n    data = {'username':'new_test','email':'test2@example.com','created':now()}\n    serializer = UserSerializer(data=data)\n    serializer.is_valid()\n    # True\n    serializer.validated_data\n    # {'username': 'new_test', 'email': 'test2@example.com', 'created': datetime.datetime(2021, 11, 12, 6, 10, 44, 85118)}}\n\nValidation\n----------\n\n.. code-block:: python\n\n    serializer = UserSerializer(data={'email': 'test'})\n    serializer.is_valid()\n    # False\n    serializer.errors\n    # {'username': ['This field is required.'], 'email': ['Enter a valid email address.'],'created': ['This field is required.']}\n\n\nField-level validation\n----------------------\n\n.. code-block:: python\n\n    import drf_turbo as dt\n\n    class UserSerializer(dt.Serializer):\n        username = dt.StrField(max_length=50)\n\n        def validate_username(self, value):\n            if 'test' not in value.lower():\n                raise dt.ValidationError(\"test must be in username\")\n            return value\n\nObject-level validation\n-----------------------\n\n.. code-block:: python\n\n    import drf_turbo as dt\n\n    class CampaignSerializer(dt.Serializer):\n        start_date = dt.DateTimeField()\n        end_date = dt.DateTimeField()\n\n        def validate(self, data):\n            if data['start_date'] \u003e data['end_date']:\n                raise dt.ValidationError(\"start_date must occur before end_date\")\n            return data\n\nNested Serializers\n------------------\n.. code-block:: python\n\n   from datetime import datetime\n   from django.utils.timezone import now\n   import drf_turbo as dt\n\n    class User:\n        def __init__(self, username, email,created=None):\n            self.username = username\n            self.email = email\n            self.created = created or datetime.now()\n\n    user = User(username='test' , email='test@example.com')\n\n    class UserSerializer(dt.Serializer):\n        username = dt.StrField(max_length=50)\n        email = dt.EmailField()\n        created = dt.DateTimeField()\n\n    class Profile :\n        def __init__(self, age=25):\n            self.age = age\n            self.user = user\n\n    profile = Profile()\n\n\n    class ProfileSerializer(dt.Serializer):\n        age = dt.IntField()\n        user = UserSerializer()\n\n\n    serializer = ProfileSerializer(profile)\n    serializer.data\n\n    # {'age' : 25 , 'user' : {'username': 'test', 'email': 'test@example.com', 'created': '2021-11-04T22:49:01.981127Z'}}\n\n\nFiltering Output\n----------------\n\ndrf-turbo provides option to enclude or exclude fields from serializer using ``only`` or ``exclude`` keywords.\n\n.. code-block:: python\n\n    serializer = UserSerializer(user,only=('id','username'))\n\n    or\n\n    serializer = ProfileSerializer(profile,exclude=('id','user__email'))\n\n    or\n\n    http://127.0.0.1:8000/user/?only=id,username\n\n\nRequired Fields\n---------------\n\nMake a field required by passing required=True. An error will be raised if the the value is missing from data during Deserializing.\n\nFor example:\n\n.. code-block:: python\n\n    class UserSerializer(dt.Serializer):\n\n        username = dt.StrField(required=True,error_messages={\"required\":\"no username\"})\n\n\n\nSpecifying Defaults\n-------------------\n\nIt will be used for the field if no input value is supplied.\n\n\nFor example:\n\n.. code-block:: python\n\n    from datetime import datetime\n\n    class UserSerializer(dt.Serializer):\n\n        birthdate = dt.DateTimeField(default=datetime(2021, 11, 05))\n\n\n\n\nModelSerializer\n---------------\n\nMapping serializer to Django model definitions.\n\nFeatures :\n\n    * It will automatically generate a set of fields for you, based on the model.\n    * It will automatically generate validators for the serializer.\n    * It includes simple default implementations of .create() and .update().\n\n.. code-block:: python\n\n    class UserSerializer(dt.ModelSerializer):\n\n        class Meta :\n            model = User\n            fields = ('id','username','email')\n\nYou can also set the fields attribute to the special value ``__all__``  to indicate that all fields in the model should be used.\n\nFor example:\n\n.. code-block:: python\n\n    class UserSerializer(dt.ModelSerializer):\n\n        class Meta :\n            model = User\n            fields = '__all__'\n\nYou can set the exclude attribute to a list of fields to be excluded from the serializer.\n\nFor example:\n\n.. code-block:: python\n\n    class UserSerializer(dt.ModelSerializer):\n\n        class Meta :\n            model = User\n            exclude = ('email',)\n\n\nRead\u0026Write only fields\n----------------------\n\n.. code-block:: python\n\n    class UserSerializer(dt.ModelSerializer):\n        class Meta:\n            model = User\n            fields = ('id', 'username', 'password','password_confirmation')\n            read_only_fields = ('username')\n            write_only_fields = ('password','password_confirmation')\n\n\nOpenApi(Swagger)\n----------------\n\nAdd drf-turbo to installed apps in ``settings.py``\n\n.. code:: python\n\n    INSTALLED_APPS = [\n        # ALL YOUR APPS\n        'drf_turbo',\n    ]\n\n\nand then register our openapi AutoSchema with DRF.\n\n.. code:: python\n\n    REST_FRAMEWORK = {\n        # YOUR SETTINGS\n        'DEFAULT_SCHEMA_CLASS': 'drf_turbo.openapi.AutoSchema',\n    }\n\n\nand finally add these lines in ``urls.py``\n\n.. code:: python\n\n    from django.views.generic import TemplateView\n    from rest_framework.schemas import get_schema_view as schema_view\n    from drf_turbo.openapi import SchemaGenerator\n\n    urlpatterns = [\n        # YOUR PATTERNS\n \tpath('openapi', schema_view(\n            title=\"Your Project\",\n            description=\"API for all things …\",\n            version=\"1.0.0\",\n            generator_class=SchemaGenerator,\n            public=True,\n        ), name='openapi-schema'),\n        path('docs/', TemplateView.as_view(\n            template_name='docs.html',\n            extra_context={'schema_url':'openapi-schema'}\n        ), name='swagger-ui'),\n    ]\n\nNow go to http://127.0.0.1:8000/docs\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n\nLicense\n------------\n* Free software: MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMng-dev-ai%2Fdrf-turbo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMng-dev-ai%2Fdrf-turbo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMng-dev-ai%2Fdrf-turbo/lists"}