Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lixxu/sanic-useragent
add user_agent to request for Sanic
https://github.com/lixxu/sanic-useragent
Last synced: 18 days ago
JSON representation
add user_agent to request for Sanic
- Host: GitHub
- URL: https://github.com/lixxu/sanic-useragent
- Owner: lixxu
- Created: 2017-02-17T07:04:55.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-27T01:37:27.000Z (over 1 year ago)
- Last Synced: 2024-11-12T22:13:14.892Z (about 1 month ago)
- Language: Python
- Size: 7.81 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-sanic - Sanic-UserAgent
README
# sanic-useragent
Add `user_agent` to request for Sanic.
## Installation
`pip install sanic-useragent`
## Usage
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-from sanic import Sanic
from sani.response import json
from sanic_useragent import SanicUserAgentapp = Sanic(__name__)
SanicUserAgent.init_app(app)
# or pass default_locale
# SanicUserAgent.init_app(app, default_locale='en_US')
# or define DEFAULT_LOCALE in app.config
# SanicUserAgent.init_app(app)@app.route('/')
async def index(request):
return json(request['user_agent'].to_dict())if __name__ == '__main__':
app.run(host='127.0.0.1', port=8000, debug=True)```