Metadata-Version: 2.1
Name: spback
Version: 0.2.7
Summary: Sun praise internal backend package.
Author-Email: svtter <svtter@qq.com>
License: NOT OPEN SOURCE
Requires-Python: <3.12,>=3.11
Requires-Dist: django<6.0,>3.2
Requires-Dist: colorlog>=6.8.2
Requires-Dist: django-ninja<2.0.0,>=1.2.0
Requires-Dist: django-ninja-extra>=0.20.7
Requires-Dist: django-ninja-jwt>=5.3.4
Requires-Dist: gevent
Requires-Dist: gunicorn
Requires-Dist: celery
Requires-Dist: django-celery-beat
Requires-Dist: django-celery-results
Requires-Dist: django-cors-headers
Requires-Dist: dj-database-url
Requires-Dist: python-dotenv
Requires-Dist: psycopg2-binary
Description-Content-Type: text/x-rst


spback (sun-praise backend) framework
=====================================


.. image:: https://img.shields.io/pypi/v/spback.svg
   :target: https://pypi.python.org/pypi/spback/
   :alt: PyPI


.. image:: https://readthedocs.org/projects/spback/badge/?version=latest
   :target: https://spback.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status
 
.. image:: https://pepy.tech/badge/spback/week
   :target: https://pepy.tech/project/spback
   :alt: Downloads


This project is built on ``django-ninja`` and ``django-ninja-extra``.

Usage
-----

Create your django project, start with the command: ``django-admin startproject conf .``.

Update ``settings.py``
^^^^^^^^^^^^^^^^^^^^^^^^^^

If you need to use the feature of ``api``\ , you need to install ``django-ninja-extra>=0.20.7``\ , ``django-ninja-jwt>=5.3.1``.

Add ``spback`` supported apps,

.. code-block:: python

   INSTALLED_APPS = [
       "django.contrib.admin",
       "django.contrib.auth",
       "django.contrib.contenttypes",
       "django.contrib.sessions",
       "django.contrib.messages",
       "django.contrib.staticfiles",
       # for example, "apis",
       ...
       "ninja_extra",  # for spback
   ]

API instance
^^^^^^^^^^^^

create api instance.

.. code-block:: python

   from spback.urls import create_api

   api = create_api()

JWT
^^^

If you want the JWT get authed, set the api with ``JWTAuth``.

.. code-block:: python

   from ninja_extra.router import Router
   from ninja_jwt.authentication import JWTAuth

   router = Router()


   @router.get("/", auth=JWTAuth())
   def protected_endpoint(request):
       return {"message": "This is a protected endpoint."}

Error handler
^^^^^^^^^^^^^

register error handler

.. code-block:: python

   from spback.handler.errors import register_error_handler

   api = register_error_handler(api)

Register to ``urls.py``
^^^^^^^^^^^^^^^^^^^^^^^^^^^

With this code, the users could register ``django-ninja`` to urls.py

.. code-block:: python

   api = create_api()
   api = register_routers(api)

   urlpatterns = [
       path("", api.urls),
   ]

Register to ``conf/urls.py``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

   from django.contrib import admin
   from django.urls import path, include

   urlpatterns = [
       path("admin/", admin.site.urls),
       path("api/", include("api.urls")),
   ]

For Developer
-------------

Use ``pdm run pip install -r requirements/dev.txt`` to install dev packages.
