ninja-api-key


Nameninja-api-key JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryDjango Ninja API Key Authentication
upload_time2024-05-09 20:14:58
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6.2
licenseNone
keywords django rest ninja auth apikey
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Ninja API Key


[![PyPI](https://img.shields.io/pypi/v/ninja-api-key.svg)](https://pypi.python.org/pypi/ninja-api-key)

[![codecov](https://codecov.io/gh/lucasrcezimbra/ninja-api-key/graph/badge.svg)](https://codecov.io/gh/lucasrcezimbra/ninja-api-key)


API Key authentication for [Django Ninja](https://django-ninja.dev/).

This is a fork from [django-ninja-apikey](https://github.com/mawassk/django-ninja-apikey).

Key Features:
- Easy integration into your projects
- Well integrated with the Admin interface
- Secure API keys due to hashing
- Works with the standard user model


## Installation

```bash
pip install ninja-api-key
```


## How to use
1. Add `ninja_apikey` to your installed apps in your Django project:
```Python
# settings.py

INSTALLED_APPS = [
    # ...
    "ninja_apikey",
]
```

2. Apply migrations
```shell
python manage.py migrate
```

3. Secure

a. the whole API
```Python
# api.py

from ninja import NinjaAPI
from ninja_apikey.security import APIKeyAuth

#  ...

api = NinjaAPI(auth=APIKeyAuth())

# ...

@api.get("/secure_endpoint")
def secure_endpoint(request):
    return f"Hello, {request.user}!"
```

b. an specific endpoint
```Python
# api.py

from ninja import NinjaAPI
from ninja_apikey.security import APIKeyAuth

#  ...

auth = APIKeyAuth()
api = NinjaAPI()

# ...

@api.get("/secure_endpoint", auth=auth)
def secure_endpoint(request):
    return f"Hello, {request.user}!"
```


## Contributing

Contributions are welcome, feel free to open an Issue or Pull Request.

```
git clone https://github.com/lucasrcezimbra/ninja-api-key
cd ninja-api-key
python -m venv .venv
source .venv/bin/activate
pip install .[test]
pre-commit install
make test
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ninja-api-key",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6.2",
    "maintainer_email": null,
    "keywords": "django, rest, ninja, auth, apikey",
    "author": null,
    "author_email": "Lucas Rangel Cezimbra <lucas@cezimbra.tec.br>, Maximilian Wassink <wassink.maximilian@protonmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b4/78/90d52f2fbfa189a6b539077379bf18be76a42de9bdc6eaff58abc813040c/ninja_api_key-1.0.0.tar.gz",
    "platform": null,
    "description": "# Ninja API Key\n\n\n[![PyPI](https://img.shields.io/pypi/v/ninja-api-key.svg)](https://pypi.python.org/pypi/ninja-api-key)\n\n[![codecov](https://codecov.io/gh/lucasrcezimbra/ninja-api-key/graph/badge.svg)](https://codecov.io/gh/lucasrcezimbra/ninja-api-key)\n\n\nAPI Key authentication for [Django Ninja](https://django-ninja.dev/).\n\nThis is a fork from [django-ninja-apikey](https://github.com/mawassk/django-ninja-apikey).\n\nKey Features:\n- Easy integration into your projects\n- Well integrated with the Admin interface\n- Secure API keys due to hashing\n- Works with the standard user model\n\n\n## Installation\n\n```bash\npip install ninja-api-key\n```\n\n\n## How to use\n1. Add `ninja_apikey` to your installed apps in your Django project:\n```Python\n# settings.py\n\nINSTALLED_APPS = [\n    # ...\n    \"ninja_apikey\",\n]\n```\n\n2. Apply migrations\n```shell\npython manage.py migrate\n```\n\n3. Secure\n\na. the whole API\n```Python\n# api.py\n\nfrom ninja import NinjaAPI\nfrom ninja_apikey.security import APIKeyAuth\n\n#  ...\n\napi = NinjaAPI(auth=APIKeyAuth())\n\n# ...\n\n@api.get(\"/secure_endpoint\")\ndef secure_endpoint(request):\n    return f\"Hello, {request.user}!\"\n```\n\nb. an specific endpoint\n```Python\n# api.py\n\nfrom ninja import NinjaAPI\nfrom ninja_apikey.security import APIKeyAuth\n\n#  ...\n\nauth = APIKeyAuth()\napi = NinjaAPI()\n\n# ...\n\n@api.get(\"/secure_endpoint\", auth=auth)\ndef secure_endpoint(request):\n    return f\"Hello, {request.user}!\"\n```\n\n\n## Contributing\n\nContributions are welcome, feel free to open an Issue or Pull Request.\n\n```\ngit clone https://github.com/lucasrcezimbra/ninja-api-key\ncd ninja-api-key\npython -m venv .venv\nsource .venv/bin/activate\npip install .[test]\npre-commit install\nmake test\n```\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Django Ninja API Key Authentication",
    "version": "1.0.0",
    "project_urls": {
        "Source": "https://github.com/lucasrcezimbra/ninja-api-key"
    },
    "split_keywords": [
        "django",
        " rest",
        " ninja",
        " auth",
        " apikey"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f74221b0041d4097051f33e017b4867a93297bdeabdf9cc371d1ab36cce1d55",
                "md5": "fcd93064fa690de0884b7413a71ee205",
                "sha256": "021ed48ef0dc73a9e291df8d7cbe351dd0e7ea3fc127a0d9201b8fd645f27ce9"
            },
            "downloads": -1,
            "filename": "ninja_api_key-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fcd93064fa690de0884b7413a71ee205",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.2",
            "size": 7957,
            "upload_time": "2024-05-09T20:14:57",
            "upload_time_iso_8601": "2024-05-09T20:14:57.199389Z",
            "url": "https://files.pythonhosted.org/packages/8f/74/221b0041d4097051f33e017b4867a93297bdeabdf9cc371d1ab36cce1d55/ninja_api_key-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b47890d52f2fbfa189a6b539077379bf18be76a42de9bdc6eaff58abc813040c",
                "md5": "541736fdac73e0f1a6f574ea07b91239",
                "sha256": "f8eb311a6ac7d31b84d889531a4cf3d7002191e0866c1069792a3e519bc37845"
            },
            "downloads": -1,
            "filename": "ninja_api_key-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "541736fdac73e0f1a6f574ea07b91239",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.2",
            "size": 6223,
            "upload_time": "2024-05-09T20:14:58",
            "upload_time_iso_8601": "2024-05-09T20:14:58.475461Z",
            "url": "https://files.pythonhosted.org/packages/b4/78/90d52f2fbfa189a6b539077379bf18be76a42de9bdc6eaff58abc813040c/ninja_api_key-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-09 20:14:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucasrcezimbra",
    "github_project": "ninja-api-key",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ninja-api-key"
}
        
Elapsed time: 0.41789s