Automated summary
This skill offers expert guidance for building high-performance REST APIs with Django Ninja using Python type hints and Pydantic.
Strengths
- Spans the full API lifecycle: input validation, response serialization, modular routing, and dependency injection
- Enforces concrete conventions such as In/Out schema naming and explicit HTTP status codes
- Ships reference snippets for authentication (API Key, JWT, RBAC), pagination, and CSRF protection
- Encourages async views, centralized error handling through ninja.errors.HttpError, and well-tagged Swagger docs
Limitations
- Assumes prior familiarity with Django, Pydantic, and the async ORM
- Referenced snippets are not embedded in the SKILL.md itself and must be consulted separately
- Does not address deployment, large-scale performance, or automated testing
Use it when designing or refactoring a Django Ninja API that needs type-safe, asynchronous, self-documenting patterns.
Skip it for Django REST Framework projects or trivial APIs that don't warrant Pydantic validation.
Security analysis
SafeThe skill is purely instructional documentation for Django Ninja API development. It does not instruct destructive actions, secret exfiltration, obfuscated payloads, or safety-disabling behavior, and it declares no tools.
No concerns found
How this analysis is madeExamples
Create an async Django Ninja endpoint for creating a User with a Pydantic UserIn schema, returning 201 with a UserOut response and 403 on failure.Set up a Django Ninja Router protected by django-ninja-jwt bearer authentication with token rotation and blacklisting enabled.Add cursor-based pagination to my Django Ninja list endpoint using the @paginate decorator with CursorPagination.name: django-ninja-skills description: Expert guidance for high-performance Django API development using Django Ninja.
Django Ninja Skills
Overview
This skill provides expert-level guidance for building RESTful APIs using Python 3.10+ type hints and Pydantic. It focuses on leveraging Django Ninja's core strengths: Asynchronous support (Async), Automatic OpenAPI/Swagger generation, and Type-safe data validation.
Core Competencies
1. Input Parsing & Validation:
- Parameter Handling: Using type hints for Path, Query, Header, and Cookie parameters.
- Request Body: Defining complex payloads using Pydantic Schemas.
- Data Ingestion: Managing Form data, file uploads, and multi-part requests.
2. Response Serialization:
- Schema Modeling: Utilizing
ModelSchemafor direct Django model mapping. - Response Control: Defining status-code-specific responses (e.g.,
{201: SuccessOut, 403: ErrorOut}). - Optimization: Implementing built-in Pagination and custom Response Renderers.
3. API Architecture:
- Modular Routing: Using
Routerto decouple business domains. - Dependency Injection: Implementing reusable authentication and logic injection.
Instructions
- Schema-First Design: Always define Pydantic Schemas for data exchange. Use
ModelSchemato map Django models, explicitly controlling field exposure viamodel_fieldsormodel_exclude. - Async Integration: Prefer
async deffor I/O-bound view functions, ensuring compatibility with Django’s asynchronous ORM features. - Standardized Error Handling: Avoid manual JSON error responses. Use
ninja.errors.HttpErroror register globalexception_handlersfor consistent API error contracts. - Injected Security: Do not manually verify users within views. Use the
authparameter inRouterorNinjaAPIto enforce authentication via dependency injection. - Documentation Standards: Every endpoint must include a docstring and use
tagsto maintain a clean and navigable Swagger UI.
Best Practices
- Naming: Suffix schema classes with
InorOut(e.g.,UserIn,UserOut) to clarify data flow. - Status Codes: Be explicit with HTTP status codes (e.g., return
201for successful creation). - Logic Separation: Keep view functions thin; move complex business logic to a dedicated
services.pylayer.
Reference Templates
Refer to snippets/schema.py for the ModelSchema definitions and field naming.
- Standard Pydantic Schema (Non-Model based)
- Model-based Schemas
- Advanced Filtering/Search Schema
- Auth/Token Schemas
Refer to snippets/crud_async.py for the standard implementation of:
- Async CRUD operations.
- Multi-status code handling (201, 204, 404).
- Integration with Django 5.0+ Async ORM.
Refer to snippets/auth.py Implementations for APIKey, JWT, and dependency-based security.
- API Key Authentication (e.g., for Internal Service-to-Service)
- JWT / Bearer Token Authentication (Standard Web Auth)
- Role-Based Access Control (RBAC) Pattern
Refer to snippets/ninja_jwt.py for integration with django-ninja-jwt.
- Detailed
NINJA_JWTconfiguration (Rotation, Blacklisting). - Synchronous and Asynchronous JWT authentication patterns.
- Custom JWT-based API Key header implementations.
Refer to snippets/csrf.py for CSRF protection patterns in Django Ninja.
- CSRF exemption and validation patterns.
- Integration with frontend CSRF tokens.
Refer to snippets/comparison.py for comparisons between anti-patterns and optimized code.
- Response Handling
- Async Usage
- Error Handling
- Authentication
Refer to snippets/pagination.py for apply pagination to a function - just apply paginate decorator:
- Default (LimitOffset): @paginate
- Page Number: @paginate(PageNumberPagination)
- Cursor: @paginate(CursorPagination)
- Custom: Create a class inheriting from PaginationBase and use @paginate(CustomPagination)
Refer to snippets/throttles.py for implementing API rate limiting and throttling:
- Global Throttling
- Router-Level Throttling
- Endpoint-Level Throttling
- 💡 Rate Format Guide
- 🛠️ How to Test Your Rate Limiting?
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/django-ninja-skills-ms1aw4yv' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/django-ninja-skills-ms1aw4yv/download' --output '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md.part' && mv '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md.part' '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md' && test -s '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/django-ninja-skills' && cp -R '.skill-downloads/django-ninja-skills-ms1aw4yv' '.claude/skills/django-ninja-skills'Cursor
test -f '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md' && test -s '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/django-ninja-skills' && cp -R '.skill-downloads/django-ninja-skills-ms1aw4yv' '.cursor/skills/django-ninja-skills'Codex
test -f '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md' && test -s '.skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/django-ninja-skills' && cp -R '.skill-downloads/django-ninja-skills-ms1aw4yv' '.agents/skills/django-ninja-skills'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/django-ninja-skills-ms1aw4yv'openskills read 'django-ninja-skills-ms1aw4yv'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/django-ninja-skills-ms1aw4yv/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
React Hook Form Best Practices
Development
Master React Hook Form: avoid anti-patterns, manage subscriptions, and handle reset, dirty state, and controlled inputs correctly.
Emotion to Mantine Migration
Development
Migrate Emotion styled-components to Mantine components with style props and CSS modules. Use when converting .styled.tsx files or removing @emotion imports.
Scope Creep Detector
Development
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad PRs, and oversized changes, then suggests keep, split, or justify actions.