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.

Source Distribution

browscap-python-0.0.16.tar.gz (8.1 kB view hashes)

Uploaded source

Built Distribution

browscap_python-0.0.16-py3-none-any.whl (11.4 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page