Skip to main content

django-pybrowscap is django middleware with support for pybrowscap

Project description

django-pybrowscap is django middleware with support for pybrowscap. It decorates request with browser attribute, which contains all possible information about the User-Agent accessing the view.



Install via pipy or copy this module into your project or into your PYTHON_PATH.

Put django_pybrowscap into INSTALLED_APPS in your projects file


Put django_pybrowscap.middleware.PybrowscapMiddleware into MIDDLEWARE_CLASSES in your projects file



django constants

# This setting will effectively turn the middleware off, to speed up requests/response while developing
PYBROWSCAP_INITIALIZE = True # Default is `not settings.DEBUG`.

# Path where browscap file is located on filesystem
PYBROWSCAP_FILE_PATH = MEDIA_ROOT+os.sep+'browscap.csv' # Default is '' (empty string)

# Proxy to use
# See:
  "http": "http://user:pass@",
  "https": "",
} # Defaults to None.

# Timeout for HTTP requets
# See:

# Tuple of regular expressions of paths that are to be ignored by the middleware
) # Defaults to an empty tupple.

# This tells middleware to reload browscap file from disk every PYBROWSCAP_RELOAD_INTERVAL seconds
PYBROWSCAP_RELOAD = True # Reload file. Default is False.
PYBROWSCAP_RELOAD_INTERVAL =  7 * 24 * 60 * 60 # Reloads browscap file once a week

Automatic Updates

Download latest version of the browscap data by executing the builtin management command::

$ python download_browscap \
--url \
--file-path /path/to/downloaded/browscap_file

You don’t need to provide any options for this command. By default, latest CSV browscap file will be downloaded and saved to settings.PYBROWSCAP_FILE_PATH. Don’t forget to set your settings.PYBROWSCAP_RELOAD = True. For convenience execute the command via cron automatically once a week::

5 8 * * 6 python download_browscap


def standard_view(request):
    if request.browser is not None and request.browser.is_crawler():
        # do something
        # do something else


Tested on evnironment

  • Xubuntu Linux 12.04 LTS precise 64-bit
  • python 2.7.3
  • python unitest
  • browscap_14_05_2012.csv from Mon, 14 May 2012 22:20:20 -0000

Running tests

To run the tests, execute one of the following commands::

$ python test
$ make test


char0n (Vladimir Gorej, CodeScale)

Project details

Download files

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

Files for django-pybrowscap, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size django-pybrowscap-1.0.0.tar.gz (8.4 kB) File type Source Python version None Upload date Hashes View

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 Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page