Skip to main content

A decorator to simplify searching and filtering in Django Ninja views.

Project description

PyPI version Python versions Build codecov License

django-ninja-search

A lightweight decorator to add filtering, searching, and sorting support to Django Ninja view functions.


✨ Features

  • Add full-text search and ordering with a decorator
  • Optional schema-based filtering
  • Works seamlessly with Django ORM and Django Ninja

📦 Installation

pip install django-ninja-search

Or with Poetry:

poetry add django-ninja-search

🚀 Usage

1. Define your model (example)

# models.py
class Item(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField()

2. Add the decorator to your view

# views.py
from ninja import Query
from ninja_schema import Schema
from django_ninja_search import searching

class ItemFilterSchema(Schema):
    pass  # You can define extra filters here if needed

@searching(
    filterSchema=ItemFilterSchema,
    search_fields=["name", "description"],
    sort_fields=["name", "description"],
)
def list_items(request, filters: ItemFilterSchema = Query(...)):
    return Item.objects.all()

This enables:

  • /?search=banana → filters by search text
  • /?ordering=name → sorts results

🧪 Running Tests

poetry install
poetry run pytest --cov=ninja_search --cov-report=html

Open the coverage report in your browser:

open htmlcov/index.html  # macOS
xdg-open htmlcov/index.html  # Linux

📤 Publishing

✅ Publish to Test PyPI

poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry publish --build -r testpypi

🚀 Publish to PyPI

poetry config repositories.pypi https://upload.pypi.org/legacy/
poetry config pypi-token.pypi <your-token-here>
poetry publish --build -r pypi

🔁 Versioning and Release

Before releasing a new version:

poetry version patch  # or minor / major
poetry build
# Publish using one of the methods above

# Tag and push
git tag v<new-version>
git push origin v<new-version>
git push origin main

📚 Metadata & Compatibility

Python Versions: 3.10, 3.11, 3.12, 3.13 Django Versions: >=5.1.0 License: MIT Project URL: https://github.com/anandrnair547/django-ninja-search PyPI: https://pypi.org/project/django-ninja-search/


🤝 Contributing

We welcome contributions! See the Contributing Guide for setup instructions, test coverage tips, release workflow, and versioning guidance.


🧾 License

MIT © Anand R Nair

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_ninja_search-0.1.4.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_ninja_search-0.1.4-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file django_ninja_search-0.1.4.tar.gz.

File metadata

  • Download URL: django_ninja_search-0.1.4.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.5.0

File hashes

Hashes for django_ninja_search-0.1.4.tar.gz
Algorithm Hash digest
SHA256 06cc392e1531ab8361317d3ce342e8bfd2941bc1b5ed2a81932cac3c89d54f9f
MD5 d06fd34b74358f8e594c88a2adfab740
BLAKE2b-256 c534e6bb4e7e289ffb5c81203ddb34c74adbb2a069bce3ff4e32032d94a40884

See more details on using hashes here.

File details

Details for the file django_ninja_search-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_ninja_search-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 21f296f8a4160c12a885e9b22313e0db035c0e3f2a5ce5580ec59a1d6554e25b
MD5 eb66c5cc05772f020d773b66835d59f8
BLAKE2b-256 815c84976c489dd8a5824dd52f66f2f0b5c4fee79fcc65efadb9836577a0d553

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page