Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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 SanicUserAgent

app = 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)

```