{"id":17100296,"url":"https://github.com/rsinger86/drf-typed","last_synced_at":"2025-04-12T23:53:34.820Z","repository":{"id":41361746,"uuid":"403136170","full_name":"rsinger86/drf-typed","owner":"rsinger86","description":"Type hints for enhanced API views and serializers.","archived":false,"fork":false,"pushed_at":"2023-03-25T20:31:10.000Z","size":802,"stargazers_count":83,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T23:53:29.919Z","etag":null,"topics":["django","django-rest-framework","serializer","type-annotations","type-hints","validation"],"latest_commit_sha":null,"homepage":"https://rsinger86.github.io/drf-typed/","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/rsinger86.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-04T19:06:20.000Z","updated_at":"2025-03-15T11:33:42.000Z","dependencies_parsed_at":"2025-02-22T13:33:47.072Z","dependency_job_id":"783c6b84-9e47-4aad-bdad-065920014b4a","html_url":"https://github.com/rsinger86/drf-typed","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsinger86%2Fdrf-typed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsinger86%2Fdrf-typed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsinger86%2Fdrf-typed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsinger86%2Fdrf-typed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rsinger86","download_url":"https://codeload.github.com/rsinger86/drf-typed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647237,"owners_count":21139083,"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":["django","django-rest-framework","serializer","type-annotations","type-hints","validation"],"created_at":"2024-10-14T15:12:58.897Z","updated_at":"2025-04-12T23:53:34.794Z","avatar_url":"https://github.com/rsinger86.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django REST - Typed\n\n[![Package version](https://badge.fury.io/py/drf-typed.svg)](https://pypi.python.org/pypi/drf-typed)\n[![Python versions](https://img.shields.io/pypi/status/drf-typed.svg)](https://img.shields.io/pypi/status/drf-typed.svg/)\n[![Python versions](https://img.shields.io/pypi/pyversions/drf-typed.svg)](https://pypi.org/project/drf-typed/)\n![PyPI - Django Version](https://img.shields.io/pypi/djversions/drf-typed)\n\nThis project extends [Django REST Framework](https://www.django-rest-framework.org/) to allow use of Python's type hints for automatically validating view parameters, as well as supporting typed attributes and annotation-generated fields on serializers.\n\nDeriving automatic behavior from type annotations has become increasingly popular with the [FastAPI](https://fastapi.tiangolo.com/) and [Django Ninja](https://django-ninja.rest-framework.com/) frameworks. The goal of this project is to provide these benefits to the DRF ecosystem.\n\nMain benefits:\n\n- View inputs can be individually declared, not buried inside all-encompassing `request` objects.\n- Type annotations can replace repetitive view validation/sanitization code.\n- Simple serializers can have their fields auto-generated from annotations\n- Validated serializer data can be accessed from attributes, with their types known to the IDE\n- [Pydantic](https://pydantic-docs.helpmanual.io/) models are compatible types for view parameters. Annotate your POST/PUT functions with them to automatically validate incoming request bodies.\n\n**Documentation**: \u003ca href=\"https://rsinger86.github.io/drf-typed/\" target=\"_blank\"\u003ehttps://rsinger86.github.io/drf-typed\u003c/a\u003e\n\n**Source Code**: \u003ca href=\"https://github.com/rsinger86/drf-typed/\" target=\"_blank\"\u003ehttps://github.com/rsinger86/drf-typed\u003c/a\u003e\n\n## Views Example\n\n```python\nfrom rest_typed.views import typed_api_view\n\n\"\"\"\nGET /users/registered/?registered_on=2019-03-03\u0026staff=yes\n\"\"\"\n\n@typed_api_view([\"GET\"])\ndef get_users(registered_on: date = None, staff: bool = None):\n    print(registered_on, is_staff)\n    # date(2019, 3, 3) True\n    data = query_orm(registered_on, is_staff)\n    return Response(data)\n```\n\n## Serializers Example\n\n```python\nfrom datetime import date\nfrom rest_typed.serializers import TSerializer\n\n\nclass MovieSerializer(TSerializer):\n    title: str          # same as: CharField(required=True, allow_null=False)\n    release_date: date  # same as: DateField(required=True, allow_null=False)\n    description = None  # same as: DateField(default=None)\n\nmovie = MovieSerializer(data={\n  \"title\": \"The Last Duel\",\n  \"release_date\": \"2021-10-15\",\n})\n\nmovie.is_valid(raise_exception=True)\n\nprint(movie.validated_data)\n\"\"\"\n  {\n    \"title\": \"The Last Duel\",\n    \"release_date\": date(2021, 10, 15),\n    \"description\": None\n  }\n\"\"\"\n\n# Or access attributes directly:\nprint(movie.title) # The Last Duel\nprint(movie.release_date) # date(2021, 10, 15)\n```\n\nThe IDE can help you understand types and auto-complete attributes:\n\n![Type Annotation](docs/images/attribute-str-type-hint.jpg)\n\n![Type Annotation](docs/images/attribute-date-auto-complete.jpg)\n\n---\n\n# Install\n\nInstall using:\n\n```\npip install drf-typed\n\n```\n\nPython 3.8 or higher is required.\n\n# Changelog\n\n## 0.3.0 (March 2023)\n\n- Adds support for nested serializers from type annotations.\n\n## 0.2.0 (January 2022)\n\n- Fixes setup.py for finding packages\n\n## 0.1.3 (October 2021)\n\n- Fixes setup.py for finding packages\n\n## 0.1.1 (October 2021)\n\n- Docs improvements\n- Updates setup.py to include stubs package\n\n## 0.1.0 (October 2021)\n\n- First release\n\n# Testing\n\nTests are found in a simplified Django project in the `/tests` folder. Install the project requirements and do `./manage.py test` to run them.\n\n# License\n\nSee [License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsinger86%2Fdrf-typed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsinger86%2Fdrf-typed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsinger86%2Fdrf-typed/lists"}