Parse User Agents with Python

It's easy to use our Browser Detection API with Python, to get the most detailed and complete approach to decoding user agents. We are always updating our custom-built user agent parser, so you'll never need to worry about updating your software libraries again! Just send a simple HTTP request and get the result instantly.

Easy to use

Simply sign up and get your API key, then include it when you make API requests.

Here's an example of calling our API with Python to decode a user agent - this will output the Browser Name, Version, Operating System Name & Version in a readable string - there are lots of extra fields in the response which you can use as well. It also checks if the web browser is up to date and warns you if it isn't.

import requests import json # Set up the request headers = { "X-API-KEY": "APIKEYGOESHERE1234567890ABCDEFGH", # Your API Key goes here. } post_data = { "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36", "parse_options": {}, # You can specify some extra parse options if you need to. } # -- Make the request result = requests.post("https://api.whatismybrowser.com/api/v2/user_agent_parse", data=json.dumps(post_data), headers=headers) # -- Decode the response result_json = result.json() # -- Copy the data to some variables for easier use parse = result_json.get("parse") version_check = result_json.get("version_check") # A basic example of outputting their Browser and Operating System # Discover all the available fields here: # https://developers.whatismybrowser.com/api/features/user-agent-parse#fields-for-plans print("You are using %s" % parse.get("simple_software_string")) # -- Check if their browser is up to date if version_check is not None: if version_check.get("is_checkable") is True: if version_check.get("is_up_to_date") is True: print("%s is up to date" % parse.get("software_name")) else: print("%s is out of date" % parse.get("software_name")) if version_check.get("latest_version"): print("The latest version is %s" % ".".join(version_check.get("latest_version"))) if version_check.get("update_url"): print("You can update here: %s" % version_check.get("update_url"))

Get the full sample code

The above snippit of code is quite straight-forward and is just intended to get you started. We have more detailed sample code for Python and many other languages. The sample code also shows you how use the other API End Points - so that you can send hundreds of user agents in a single batch, get all the latest web browser and operating system version numbers, or even download or search our database of over 410 million user agents.

Why Parse User Agents with Python?

There are lots of reasons you might need to use Python to parse user agents. The primary one is that you need to warn your visitors that their web browser is out of date and might not work on your site. You might also want to customise your content, Calls to Action, and promotions based on the type of hardware and/or software that they're using.

As well as that, decoding your visitor's user agents can help you understand the general trends on your website - how many visitors access your site on mobile devices each month? What about Smart TVs?! With our API you can find out the answer to these sorts of questions, and use the information to help plan, design, and run your site even better.

Get started now

The API is free to use and easy to set up, so why not get started right now.

Do you have a question? Get in touch! We'd love to help you.