{"id":31856662,"url":"https://github.com/eadwincode/ninja-schema","last_synced_at":"2025-10-12T14:22:24.314Z","repository":{"id":41379259,"uuid":"400984586","full_name":"eadwinCode/ninja-schema","owner":"eadwinCode","description":"Ninja Schema is Pydantic full support for Django ORM. ","archived":false,"fork":false,"pushed_at":"2025-10-06T16:10:09.000Z","size":205,"stargazers_count":59,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-06T18:20:24.396Z","etag":null,"topics":["django","django-ninja","django-ninja-extra","django-schema","djantic","pydantic","pydantic-django"],"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/eadwinCode.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-08-29T08:00:12.000Z","updated_at":"2025-10-06T16:10:06.000Z","dependencies_parsed_at":"2024-06-21T19:01:43.402Z","dependency_job_id":"ec4c4b3a-d777-4741-b310-ec7160c3c389","html_url":"https://github.com/eadwinCode/ninja-schema","commit_stats":{"total_commits":88,"total_committers":2,"mean_commits":44.0,"dds":0.09090909090909094,"last_synced_commit":"0df47c89db3d2bd5a6c6f4a0c4b508d6a8e7e5c2"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/eadwinCode/ninja-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadwinCode%2Fninja-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadwinCode%2Fninja-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadwinCode%2Fninja-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadwinCode%2Fninja-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eadwinCode","download_url":"https://codeload.github.com/eadwinCode/ninja-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadwinCode%2Fninja-schema/sbom","scorecard":{"id":363510,"data":{"date":"2025-08-11","repo":{"name":"github.com/eadwinCode/ninja-schema","commit":"7490b9a5e4a4745bc7fa631464d21a7d25863d53"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.5,"checks":[{"name":"Code-Review","score":3,"reason":"Found 2/6 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":10,"reason":"12 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/publish.yml:1","Warn: no topLevel permission defined: .github/workflows/test.yml:1","Warn: no topLevel permission defined: .github/workflows/test_full.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/publish.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test_full.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/test_full.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test_full.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/test_full.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test_full.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/test_full.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test_full.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/eadwinCode/ninja-schema/test_full.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/publish.yml:19","Warn: pipCommand not pinned by hash: .github/workflows/publish.yml:23","Warn: pipCommand not pinned by hash: .github/workflows/test.yml:20","Warn: pipCommand not pinned by hash: .github/workflows/test_full.yml:27","Warn: pipCommand not pinned by hash: .github/workflows/test_full.yml:30","Warn: pipCommand not pinned by hash: .github/workflows/test_full.yml:33","Warn: pipCommand not pinned by hash: .github/workflows/test_full.yml:46","Info:   0 out of   8 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   7 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/publish.yml:9"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 28 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T11:20:59.546Z","repository_id":41379259,"created_at":"2025-08-18T11:20:59.546Z","updated_at":"2025-08-18T11:20:59.546Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011595,"owners_count":26084964,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-ninja","django-ninja-extra","django-schema","djantic","pydantic","pydantic-django"],"created_at":"2025-10-12T14:22:23.271Z","updated_at":"2025-10-12T14:22:24.305Z","avatar_url":"https://github.com/eadwinCode.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Test](https://github.com/eadwinCode/ninja-schema/workflows/Test/badge.svg)\n[![PyPI version](https://badge.fury.io/py/ninja-schema.svg)](https://badge.fury.io/py/ninja-schema)\n[![PyPI version](https://img.shields.io/pypi/pyversions/ninja-schema.svg)](https://pypi.python.org/pypi/ninja-schema)\n[![PyPI version](https://img.shields.io/pypi/djversions/ninja-schema.svg)](https://pypi.python.org/pypi/ninja-schema)\n[![Codecov](https://img.shields.io/codecov/c/gh/eadwinCode/ninja-schema)](https://codecov.io/gh/eadwinCode/ninja-schema)\n[![Downloads](https://static.pepy.tech/badge/ninja-schema)](https://pepy.tech/project/ninja-schema)\n\n# Ninja Schema\nNinja Schema converts your Django ORM models to Pydantic schemas with more Pydantic features supported.\n\n**Inspired by**: [django-ninja](https://django-ninja.rest-framework.com/) and [djantic](https://jordaneremieff.github.io/djantic/)\n### Notice\nStarting version `0.13.4`, Ninja schema will support both v1 and v2 of pydantic library and will closely monitor V1 support on pydantic package.\n\n### Requirements\nPython \u003e= 3.8\ndjango \u003e= 3\npydantic \u003e= 1.6\n \n**Key features:**\n- **Custom Field Support**: Ninja Schema converts django model to native pydantic types which gives you quick field validation out of the box. eg Enums, email, IPAddress, URLs, JSON, etc\n- **Field Validator**: Fields can be validated with **model_validator** just like pydantic **[validator](https://pydantic-docs.helpmanual.io/usage/validators/)** or **[root_validator](https://pydantic-docs.helpmanual.io/usage/validators/)**. \n  \n## Installation\n\n```\npip install ninja-schema\n```\n\n## Example\nCheckout this sample project: https://github.com/eadwinCode/bookstoreapi\n\n\n## Configuration Properties\n- **model**: Django Model\n- **include**: Fields to include, `default: '__all__'`. Please note that when include = `__all__`, model's **PK** becomes optional\n- **exclude**: Fields to exclude, `default: set()`\n- **optional**: Fields to mark optional,` default: set()`\n`optional = '__all__'` will make all schema fields optional \n- **depth**: defines depth to nested generated schema, `default: 0`\n\n## `model_validator(*args, **kwargs)`\n**model_validator** is a substitute for **pydantic [validator](https://pydantic-docs.helpmanual.io/usage/validators/)** used for pre and post fields validation.\nThere functionalities are the same. More info [pydantic validators](https://pydantic-docs.helpmanual.io/usage/validators/)\n```Python\nfrom django.contrib.auth import get_user_model\nfrom ninja_schema import ModelSchema, model_validator\n\nUserModel = get_user_model()\n\n\nclass CreateUserSchema(ModelSchema):\n    class Config:\n        model = UserModel\n        include = ['username', 'email', 'password']\n\n    @model_validator('username')\n    def validate_unique_username(cls, value_data: str) -\u003e str:\n        if UserModel.objects.filter(username__icontains=value_data).exists():\n            raise ValueError('Username exists')\n        return value_data\n```\n##  `from_orm(cls, obj: Any)`\nYou can generate a schema instance from your django model instance\n```Python\nfrom django.contrib.auth import get_user_model\nfrom ninja_schema import ModelSchema, model_validator\n\nUserModel = get_user_model()\nnew_user = UserModel.objects.create_user(\n    username='eadwin', email='eadwin@example.com', \n    password='password', first_name='Emeka', last_name='Okoro'\n)\n\n\nclass UserSchema(ModelSchema):\n    class Config:\n        model = UserModel\n        include = ['id','first_name', 'last_name', 'username', 'email']\n\nschema = UserSchema.from_orm(new_user)\nprint(schema.json(indent=2)\n{\n    \"id\": 1,\n    \"first_name\": \"Emeka\",\n    \"last_name\": \"Okoro\",\n    \"email\": \"eadwin@example.com\",\n    \"username\": \"eadwin\",\n}\n```\n\n## `apply_to_model(self, model_instance, **kwargs)`\nYou can transfer data from your ModelSchema to Django Model instance using the `apply` function.\nThe `apply_to_model` function uses Pydantic model `.dict` function, `dict` function filtering that can be passed as `kwargs` to the `.apply` function.\n\nFor more info, visit [Pydantic model export](https://pydantic-docs.helpmanual.io/usage/exporting_models/)\n```Python\nfrom django.contrib.auth import get_user_model\nfrom ninja_schema import ModelSchema\n\nUserModel = get_user_model()\nnew_user = UserModel.objects.create_user(username='eadwin', email='eadwin@example.com', password='password')\n\n\nclass UpdateUserSchema(ModelSchema):\n    class Config:\n        model = UserModel\n        include = ['first_name', 'last_name', 'username']\n        optional = ['username']  # `username` is now optional\n\nschema = UpdateUserSchema(first_name='Emeka', last_name='Okoro')\nschema.apply_to_model(new_user, exclude_none=True)\n\nassert new_user.first_name == 'Emeka' # True\nassert new_user.username == 'eadwin' # True\n```\n\n## Generated Schema Sample\n\n```Python\nfrom django.contrib.auth import get_user_model\nfrom ninja_schema import ModelSchema, model_validator\n\nUserModel = get_user_model()\n\n\nclass UserSchema(ModelSchema):\n    class Config:\n        model = UserModel\n        include = '__all__'\n        depth = 2\n\n        \nprint(UserSchema.schema())\n\n{\n    \"title\": \"UserSchema\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"id\": {\"title\": \"Id\", \"extra\": {}, \"type\": \"integer\"},\n        \"password\": {\"title\": \"Password\", \"maxLength\": 128, \"type\": \"string\"},\n        \"last_login\": {\"title\": \"Last Login\",\"type\": \"string\", \"format\": \"date-time\"},\n        \"is_superuser\": {\"title\": \"Superuser Status\",\n            \"description\": \"Designates that this user has all permissions without explicitly assigning them.\",\n            \"default\": false,\n            \"type\": \"boolean\"\n        },\n        \"username\": {\n            \"title\": \"Username\",\n            \"description\": \"Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.\",\n            \"maxLength\": 150,\n            \"type\": \"string\"\n        },\n        \"first_name\": {\n            \"title\": \"First Name\",\n            \"maxLength\": 150,\n            \"type\": \"string\"\n        },\n        \"last_name\": {\n            \"title\": \"Last Name\",\n            \"maxLength\": 150,\n            \"type\": \"string\"\n        },\n        \"email\": {\n            \"title\": \"Email Address\",\n            \"type\": \"string\",\n            \"format\": \"email\"\n        },\n        \"is_staff\": {\n            \"title\": \"Staff Status\",\n            \"description\": \"Designates whether the user can log into this admin site.\",\n            \"default\": false,\n            \"type\": \"boolean\"\n        },\n        \"is_active\": {\n            \"title\": \"Active\",\n            \"description\": \"Designates whether this user should be treated as active. Unselect this instead of deleting accounts.\",\n            \"default\": true,\n            \"type\": \"boolean\"\n        },\n        \"date_joined\": {\n            \"title\": \"Date Joined\",\n            \"type\": \"string\",\n            \"format\": \"date-time\"\n        },\n        \"groups\": {\n            \"title\": \"Groups\",\n            \"description\": \"The groups this user belongs to. A user will get all permissions granted to each of their groups.\",\n            \"type\": \"array\",\n            \"items\": {\n                \"$ref\": \"#/definitions/Group\"\n            }\n        },\n        \"user_permissions\": {\n            \"title\": \"User Permissions\",\n            \"description\": \"Specific permissions for this user.\",\n            \"type\": \"array\",\n            \"items\": {\n                \"$ref\": \"#/definitions/Permission\"\n            }\n        }\n    },\n    \"required\": [\n        \"password\",\n        \"username\",\n        \"groups\",\n        \"user_permissions\"\n    ],\n    \"definitions\": {\n        \"Permission\": {\n            \"title\": \"Permission\",\n            \"type\": \"object\",\n            \"properties\": {\n                \"id\": {\n                    \"title\": \"Id\",\n                    \"extra\": {},\n                    \"type\": \"integer\"\n                },\n                \"name\": {\n                    \"title\": \"Name\",\n                    \"maxLength\": 255,\n                    \"type\": \"string\"\n                },\n                \"content_type_id\": {\n                    \"title\": \"Content Type\",\n                    \"type\": \"integer\"\n                },\n                \"codename\": {\n                    \"title\": \"Codename\",\n                    \"maxLength\": 100,\n                    \"type\": \"string\"\n                }\n            },\n            \"required\": [\n                \"name\",\n                \"content_type_id\",\n                \"codename\"\n            ]\n        },\n        \"Group\": {\n            \"title\": \"Group\",\n            \"type\": \"object\",\n            \"properties\": {\n                \"id\": {\n                    \"title\": \"Id\",\n                    \"extra\": {},\n                    \"type\": \"integer\"\n                },\n                \"name\": {\n                    \"title\": \"Name\",\n                    \"maxLength\": 150,\n                    \"type\": \"string\"\n                },\n                \"permissions\": {\n                    \"title\": \"Permissions\",\n                    \"type\": \"array\",\n                    \"items\": {\n                        \"$ref\": \"#/definitions/Permission\"\n                    }\n                }\n            },\n            \"required\": [\n                \"name\",\n                \"permissions\"\n            ]\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feadwincode%2Fninja-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feadwincode%2Fninja-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feadwincode%2Fninja-schema/lists"}