Skip to main content

Python Browscap Library.

Project description

Detect browser

import redis
import browscap
from browscap.cache.redis import RedisCache

ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"
redis_cache = redis.Redis(db=5)
bc = browscap.Browscap(cache=RedisCache(redis_cache))
browser=bc.get_browser(ua)

Detect browser with asyncio

from pprint import pprint
import asyncio
import asyncio_redis
from browscap.aio import BrowscapAsync
from browscap.aio.cache.redis import RedisPoolAioCache

loop = asyncio.get_event_loop()

@asyncio.coroutine
def get_browser():
    ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"

    redis_cache = await aioredis.create_pool(('localhost', 6379), minsize=5, maxsize=100)
    bc = BrowscapAsync(cache=RedisPoolAioCache(redis_cache))
    browser = yield from bc.get_browser(ua)

    cache.close_connection()
    return browser


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    browser = loop.run_until_complete(get_browser())
    pprint(browser)

Update base

import redis
import browscap
from browscap.cache.redis import RedisCache
from browscap import IniLoader

redis_cache = redis.Redis(db=5)
bc = browscap.Browscap(cache=RedisCache(redis_cache))
bc.update(type=IniLoader.PHP_INI_FULL)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
browscap_python-0.0.16-py3-none-any.whl (11.4 kB) Copy SHA256 hash SHA256 Wheel py3
browscap-python-0.0.16.tar.gz (8.1 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page