python-user-agents: Effortless User Agent String Parsing in Python

This repository profile is provided by osrepos.com, an open source repository discovery platform.

python-user-agents: Effortless User Agent String Parsing in Python

Summary

python-user-agents is a powerful Python library designed to simplify the identification of devices, such as mobile phones, tablets, and PCs, by parsing browser user agent strings. It allows developers to easily determine device capabilities like touch support and categorize user agents as mobile, tablet, or desktop. This tool is essential for tailoring user experiences based on device characteristics.

Repository Information

Analyzed by OSRepos on November 19, 2025

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

python-user-agents is a powerful Python library designed to simplify the identification and detection of devices like mobile phones, tablets, and their capabilities by parsing browser user agent strings. Its primary goal is to reliably determine whether a user agent represents a mobile, tablet, or PC-based device, and if it possesses touch capabilities. The library leverages the robust ua-parser for the actual parsing of raw user agent strings.

Installation

Installing python-user-agents is straightforward. The library is hosted on PyPI and can be installed using pip:

pip install pyyaml ua-parser user-agents

Alternatively, you can obtain the latest source code directly from its GitHub repository and install it manually.

Examples

The library provides easy access to various basic information through browser, device, and os attributes. Here's how you can parse a user agent string and access its properties:

from user_agents import parse

# iPhone's user agent string
ua_string = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3'
user_agent = parse(ua_string)

# Accessing user agent's browser attributes
print(user_agent.browser)  # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')
print(user_agent.browser.family)  # returns 'Mobile Safari'
print(user_agent.browser.version)  # returns (5, 1)
print(user_agent.browser.version_string)   # returns '5.1'

# Accessing user agent's operating system properties
print(user_agent.os)  # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')
print(user_agent.os.family)  # returns 'iOS'
print(user_agent.os.version)  # returns (5, 1)
print(user_agent.os.version_string)  # returns '5.1'

# Accessing user agent's device properties
print(user_agent.device)  # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone')
print(user_agent.device.family)  # returns 'iPhone'
print(user_agent.device.brand) # returns 'Apple'
print(user_agent.device.model) # returns 'iPhone'

# Viewing a pretty string version
print(str(user_agent)) # returns "iPhone / iOS 5.1 / Mobile Safari 5.1"

Beyond basic attributes, user_agents also exposes "sophisticated" attributes for common device types:

  • is_mobile: True if identified as a mobile phone.
  • is_tablet: True if identified as a tablet device.
  • is_pc: True if running a traditional "desktop" OS.
  • is_touch_capable: True if the user agent has touch capabilities.
  • is_bot: True if the user agent is a search engine crawler/spider.

Here are more examples demonstrating these advanced attributes:

from user_agents import parse

# Let's start from an old, non touch Blackberry device
ua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba'
user_agent = parse(ua_string)
print(user_agent.is_mobile) # returns True
print(user_agent.is_tablet) # returns False
print(user_agent.is_touch_capable) # returns False
print(user_agent.is_pc) # returns False
print(user_agent.is_bot) # returns False
print(str(user_agent)) # returns "BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700"

# Now a Samsung Galaxy S3
ua_string = 'Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
user_agent = parse(ua_string)
print(user_agent.is_mobile) # returns True
print(user_agent.is_tablet) # returns False
print(user_agent.is_touch_capable) # returns True
print(user_agent.is_pc) # returns False
print(user_agent.is_bot) # returns False
print(str(user_agent)) # returns "Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4"

# iPad's user agent string
ua_string = 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10'
user_agent = parse(ua_string)
print(user_agent.is_mobile) # returns False
print(user_agent.is_tablet) # returns True
print(user_agent.is_touch_capable) # returns True
print(user_agent.is_pc) # returns False
print(user_agent.is_bot) # returns False
print(str(user_agent)) # returns "iPad / iOS 3.2 / Mobile Safari 4.0.4"

Why Use python-user-agents?

This library is invaluable for developers who need to adapt their web applications or services based on the client's device. By accurately parsing user agent strings, you can:

  • Enhance User Experience: Deliver optimized content and layouts for mobile, tablet, or desktop users.
  • Improve Analytics: Gain deeper insights into your audience's device preferences and usage patterns.
  • Implement Device-Specific Logic: Apply different business rules or features depending on the device type or its capabilities, such as touch support.
  • Identify Bots: Easily distinguish between human users and automated crawlers or spiders, which can be crucial for security, analytics, or content delivery.

Links

Related repositories

Similar repositories that may be relevant next.

OpenMontage: The First Open-Source, Agentic Video Production System

OpenMontage: The First Open-Source, Agentic Video Production System

June 29, 2026

OpenMontage is the world's first open-source, agentic video production system, designed to transform your AI coding assistant into a full video production studio. It features 12 pipelines, 52 tools, and over 500 agent skills, enabling end-to-end video creation from a simple prompt. This powerful tool handles research, scripting, asset generation, editing, and final composition, including the unique ability to produce real video from stock footage.

agentic-aivideo-productionopen-source
MarkLLM: An Open-Source Toolkit for LLM Watermarking

MarkLLM: An Open-Source Toolkit for LLM Watermarking

June 23, 2026

MarkLLM is an open-source toolkit designed to simplify the research and application of watermarking technologies for large language models (LLMs). It offers a unified framework for implementing various watermarking algorithms, alongside robust visualization and comprehensive evaluation tools. This toolkit helps researchers and the broader community understand and assess the authenticity and origin of machine-generated text.

large-language-modelsllmsafety
Agent-Reach: Empower Your AI Agents with Internet Access, Zero API Fees

Agent-Reach: Empower Your AI Agents with Internet Access, Zero API Fees

June 21, 2026

Agent-Reach is a powerful GitHub repository that equips AI agents with the ability to access and search the entire internet, including platforms like Twitter, Reddit, YouTube, and Bilibili. It provides a streamlined CLI experience, eliminating the need for complex API configurations and associated fees. This project ensures your AI agent can "see" and interact with web content effortlessly.

ai-agentagent-infrastructureai-search
REAL Video Enhancer: AI-Powered Video Interpolation, Upscaling, and Denoising

REAL Video Enhancer: AI-Powered Video Interpolation, Upscaling, and Denoising

June 19, 2026

REAL Video Enhancer is a powerful open-source application designed to enhance video quality across Linux, Windows, and macOS. It leverages AI models for advanced video processing tasks such as frame interpolation, upscaling, decompression, and denoising. This tool provides a modern alternative to older software, making high-quality video enhancement accessible to a wider audience.

video-enhancementaiupscaling

Source repository

Open the original repository on GitHub.

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️