Python Device Detector
51Degrees Mobile Detector for Python (version 2.6 or higher) allows fetching properties of mobile devices based on user agent strings. All detection packages are very efficient Python wrappers of the pattern-based and trie-based `C detection solutions. The detector provides intelligence about the device, operating system and browser accessing a web site at run time, enabling developers and designers to adapt the initial response from the server. Existing web sites can be converted to support mobile devices quickly. The solution can be combined with emerging methodologies such as responsive design or progressive enhancement to produce great results quickly.
Django Middleware - Operational Overview
When an HTTP request is received and device data does not already exists in the session the solution will identify a family (or families) the device belongs to and assign a handler for each family. Handlers significantly improve performance over designs that do not perform this initial segmentation. For example an Android 3 based device will be assigned to an Android 3 handler, immediately narrowing the individual devices to be checked against.
Each handler will then check the requesting device against each of its device generating a score for each. The device with the lowest score will win and the properties associated with that device will be returned. A score of zero indicates an exact match.
Sometimes more than one device will be found with equal score. A different algorithm which is focused on matching the initial section of the user agent string is then used to narrow down a single device.
The matched device is stored in the session if available to avoid the need to repeat this process for subsequent requests.