# Netcord
Package for authentication with Discord API
## Installing
```
pip install netcord
```
## Example
```py
# main.py
import uvicorn
from pydantic import BaseModel
from os import getenv
from netcord import Netcord
from fastapi import FastAPI, Request
from fastapi import HTTPException
app = FastAPI(title='Your Site')
CLIENT_ID = getenv('CLIENT_ID')
CLIENT_SECRET = getenv('CLIENT_SECRET')
netcord = Netcord(CLIENT_ID, CLIENT_SECRET)
class RequestData(BaseModel):
code: str
state: str
@app.get('/auth/login')
async def login(session_id: str):
return {'url': netcord.generate_auth_url(session_id)}
@app.post('/auth/callback')
async def callback(session_id: str, data: RequestData):
try:
netcord.check_state(session_id, data.state)
tokens = await netcord.get_access_token(data.code)
user = await netcord.get_user(tokens.access_token)
return {'user': user.dict()}
except ValueError as error:
raise HTTPException(status_code=400, detail=str(error))
if __name__ == '__main__':
uvicorn.run(app, reload=True, log_level=20)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "netcord",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "netcord, discord, oauth2",
"author": "netrix-team",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/db/99/26f6fb364f14dbbcd8191a89aa299718ee7300e9876fe2b038f6cb8e8832/netcord-1.2.2.tar.gz",
"platform": null,
"description": "# Netcord\nPackage for authentication with Discord API\n\n## Installing\n```\npip install netcord\n```\n\n## Example\n```py\n# main.py\n\nimport uvicorn\nfrom pydantic import BaseModel\n\nfrom os import getenv\nfrom netcord import Netcord\n\nfrom fastapi import FastAPI, Request\nfrom fastapi import HTTPException\n\napp = FastAPI(title='Your Site')\n\nCLIENT_ID = getenv('CLIENT_ID')\nCLIENT_SECRET = getenv('CLIENT_SECRET')\nnetcord = Netcord(CLIENT_ID, CLIENT_SECRET)\n\n\nclass RequestData(BaseModel):\n code: str\n state: str\n\n\n@app.get('/auth/login')\nasync def login(session_id: str):\n return {'url': netcord.generate_auth_url(session_id)}\n\n\n@app.post('/auth/callback')\nasync def callback(session_id: str, data: RequestData):\n try:\n netcord.check_state(session_id, data.state)\n tokens = await netcord.get_access_token(data.code)\n\n user = await netcord.get_user(tokens.access_token)\n return {'user': user.dict()}\n \n except ValueError as error:\n raise HTTPException(status_code=400, detail=str(error))\n\n\nif __name__ == '__main__':\n uvicorn.run(app, reload=True, log_level=20)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Package for authentication with Discord API",
"version": "1.2.2",
"project_urls": {
"Docs": "https://netcord.readthedocs.io/en/latest/",
"GitHub": "https://github.com/netrix-team/netcord",
"Homepage": "https://github.com/netrix-team/netcord"
},
"split_keywords": [
"netcord",
" discord",
" oauth2"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a5949b908361a99ac4f41d9f905d982cc065a7f113cd02ec5a037116182583df",
"md5": "ffcf86f2190f85f9d255d0ed92c8e739",
"sha256": "a58dd3a2df7fe9c53d0859008c8f355d592c52f25d2a02bdfd5aa5f30c81dad1"
},
"downloads": -1,
"filename": "netcord-1.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ffcf86f2190f85f9d255d0ed92c8e739",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 7679,
"upload_time": "2024-06-26T16:42:14",
"upload_time_iso_8601": "2024-06-26T16:42:14.340742Z",
"url": "https://files.pythonhosted.org/packages/a5/94/9b908361a99ac4f41d9f905d982cc065a7f113cd02ec5a037116182583df/netcord-1.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "db9926f6fb364f14dbbcd8191a89aa299718ee7300e9876fe2b038f6cb8e8832",
"md5": "b6f5a4710928d9273d331ca1f5e5d01c",
"sha256": "0f56276b7f09b8c5ebd4a4e0e31681feb46566eb5302fc80476bcfe9d7b9b293"
},
"downloads": -1,
"filename": "netcord-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "b6f5a4710928d9273d331ca1f5e5d01c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 6835,
"upload_time": "2024-06-26T16:42:15",
"upload_time_iso_8601": "2024-06-26T16:42:15.264636Z",
"url": "https://files.pythonhosted.org/packages/db/99/26f6fb364f14dbbcd8191a89aa299718ee7300e9876fe2b038f6cb8e8832/netcord-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-26 16:42:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "netrix-team",
"github_project": "netcord",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "flake8",
"specs": [
[
"==",
"7.0.0"
]
]
},
{
"name": "aiohttp",
"specs": [
[
">=",
"3.9.4"
]
]
},
{
"name": "pydantic",
"specs": [
[
">=",
"2.7.4"
]
]
},
{
"name": "fastapi",
"specs": [
[
">=",
"0.111.0"
]
]
}
],
"lcname": "netcord"
}