Skip to main content
https://img.shields.io/travis/abhishek72850/cherry-ua.svg?style=for-the-badge https://img.shields.io/codecov/c/github/abhishek72850/cherry-ua/master?style=for-the-badge https://img.shields.io/pypi/v/cherry-ua.svg?style=for-the-badge https://img.shields.io/github/contributors/abhishek72850/cherry-ua.svg?style=for-the-badge https://img.shields.io/github/forks/abhishek72850/cherry-ua.svg?style=for-the-badge https://img.shields.io/github/stars/abhishek72850/cherry-ua.svg?style=for-the-badge https://img.shields.io/github/issues/abhishek72850/cherry-ua.svg?style=for-the-badge

Cherry UserAgent (cherry-ua)

This is an advanced search and generate user agent python library, the user agents can be generated based on various search parameters, it supports an advanced form of applying search filters.

Database

It uses Whatismybrowser premium database which consists of more than 91+ Million user agents, which ensures everytime it generates unique random user agents.

Compatibility

The library uses as much as possible inbuilt modules, so it support all major python version.

Installation

pip install cherry-ua

Usage

  • The simplest way to use this library is:

from cherry_ua import UserAgent

ua = UserAgent()
ua.get_random()
  • To refresh the User Agent dataset

ua.refresh()
  • To get the size of User Agent dataset

ua.size()
  • To get specifc search filter query

ua.get('device')
  • To set specific search filter query

ua.set('device', 'eq("mobile")')
  • To get all the search filters

ua.get_all_filters()
  • To set multiple searcg filter queries

ua.set_search_filters(device='eq("mobile")')

Search Filters

The UserAgent class support’s multiple search parameters which can be used to get only the user agent which satisfies your requirements. The parameters are:

  • device

    Datatype : String
    Supported Operators : eq, ne, contains
    Description : This Signifies for which type of device you want user agent for.
ua = UserAgent(device="eq('mobile')")
# or
ua.set('device', "eq('mobile')")
# or
ua.set_search_filters(device="eq('mobile')")
  • os_name

    Datatype : String
    Supported Operators : eq, ne, contains
    Description : This Signifies for which OS (operating system) you want user agent for.
ua = UserAgent(os_name="eq('windows')")
# or
ua.set('os_name', "eq('windows')")
# or
ua.set_search_filters(os_name="eq('windows')")
  • os_version

    Datatype : Integer
    Supported Operators : eq, lt, lte, gt, gte, ne
    Description : This Signifies for which OS version you want user agent for.

    > This is an Integer field, so it won’t take quotes inside the operator’s

ua = UserAgent(os_version="eq(8)")
# or
ua.set('os_version', "eq(8)")
# or
ua.set_search_filters(os_version="eq(8)")
  • browser

    Datatype : String
    Supported Operators : eq, ne, contains
    Description : This Signifies for which browser you want user agent for.
ua = UserAgent(browser="eq('chrome')")
# or
ua.set('browser', "eq('chrome')")
# or
ua.set_search_filters(browser="eq('chrome')")
  • browser_engine

    Datatype : String
    Supported Operators : eq, ne, contains
    Description : This Signifies for which type of device you want user agent for.
ua = UserAgent(browser_engine="eq('blink')")
# or
ua.set('browser_engine', "eq('blink')")
# or
ua.set_search_filters(browser_engine="eq('blink')")
  • browser_version

    Datatype : Integer
    Supported Operators : eq, lt, lte, gt, gte, ne
    Description : This Signifies for which type of device you want user agent for.
ua = UserAgent(browser_version="eq(90)")
# or
ua.set('browser_version', "eq(90)")
# or
ua.set_search_filters(browser_version="eq(90)")
  • limit

    Datatype : Integer
    Supported Operators : eq, lt, lte, gt, gte, ne
    Description : This Signifies for which type of device you want user agent for.

    Note: Limit should be in the range of 1-10000

ua = UserAgent(limit=1000)
# or
ua.set('limit', 1000)
# or
ua.set_search_filters(limit=1000)

Search Filter Operators

To add the support for relative searching the filter’s support some operators just like SQL, which gives the flexibility to seearch in more customized way, the operators it supports are:

Note: More complex filter can result in less number of user agents as compared to what limit is set

  • eq

    Supported datatype : String, Integer
    Description : This operator matches the exact value given
ua.set('device', "eq('mobile')")
# matches user agent whose device is mobile
  • lt

    Supported datatype : Integer
    Description : This operator matches if the value of field is less than the given value
ua.set('os_version', "lt(8)")
# matches user agent whose os version is less than 8
  • gt

    Supported datatype : Integer
    Description : This operator matches if the value of field is greater than the given value
ua.set('os_version', "gt(8)")
# matches user agent whose os version is greater than 8
  • lte

    Supported datatype : Integer
    Description : This operator matches if the value of field is less or equal to the given value
ua.set('os_version', "lte(8)")
# matches user agent whose os version is less or equal to 8
  • gte

    Supported datatype : Integer
    Description : This operator matches if the value of field is greater or equal to the given value
ua.set('os_version', "gte(8)")
# matches user agent whose os version is greater or equal to 8
  • ne

    Supported datatype : String, Integer
    Description : This operator matches if the value of field is not equal to the given value
ua.set('device', "ne('mobile')")
# matches user agent whose device is not equal to mobile
  • contains (beta)

    Supported datatype : String
    Description : This operator matches if the field value contains the given value

    > This is still is beta stage, so might not work as you expect

ua.set('device', "eq('mobile')")
# matches user agent whose device contains the word "mobile"

Operator Chaining

The filter query also supports if you want to chain multiple operators, the supported operator chaining are:

  • and

    Description : The “and” operator chains multiple operator describing as it should matches all the operator values.

ua.set('device', "ne('mobile').and.ne('pc')")
# It matches user agent which has device value not equal to mobile and pc

# It can also be used to chaining multiple different operators
ua.set('os_version', "gt(5).and.lt(8)")
# It matches user agents which has os version greater than 5 and less than 8
  • or

    Description : The “or” operator chains multiple operator describing as it should matches any one of the operator values.

ua.set('device', "ne('mobile').or.ne('pc')")
# It matches user agent which has device value not equal to mobile or pc

# It can also be used to chaining multiple different operators
ua.set('os_version', "eq(5).or.gt(8)")
# It matches user agents which has os version equal to 5 or greater than 8

UserAgent class Functions

Function

Parameters

Description

Returns

get_random()

Returns random user agent based on given search parameters if given.

String

refresh()

Download and loads fresh set of User agent

size()

Return size of user agent downloaded dataset

Integer

get()

(filter_name : str)

Returns value of given search parameters

String

set()

(filter_name : str, query : str)

Sets specific given search parameter

get_all_filters()

Returns all the search filters

Dict

set_search_filters()

(kwargs)

Sets multiple search parameters

Issues

If facing any issues in the library usage, please feel free to raise the issue in github issue tracker, since i am the only sole developer of this project it might get delayed to get it resolved but i’ll definetly try to resolve it.

Donate :pray:

This library itself doesn’t need much maintenance, but since i am using a premium server to ensure faster and better API performance to search and get user agents, so i have to pay bills to keep it running, as i committed to keep it running but with a certain limitation, which i will remove if i get enough donation to support this open source project and also i will publish the server side code once it gets enough popularity so that others can also look into it, and may suggest some improvements.

https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif

Metadata

Release files for cherry-ua-staging 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cherry-ua-staging 0.1.0
File Size Uploaded
cherry-ua-staging-0.1.0.tar.gz 18.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cherry-ua-staging 0.1.0
File Interpreter ABI Platform
cherry_ua_staging-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.2 kB

Release files / cherry-ua-staging-0.1.0.tar.gz

Download URL cherry-ua-staging-0.1.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3c70134018dd46b1d255c2283666d5883dc623f28953c7dacfbfc87fee5814ae
BLAKE2b-256 checksum
How to use checksums
98c664170040d29df456320a64500d8d68f13148e8ce8911b1aeb0426b3dabc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

Release files / cherry_ua_staging-0.1.0-py3-none-any.whl

Download URL cherry_ua_staging-0.1.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df4407496c7cf83f95472e379c33250bcaeb3b845559dfe40362f055e82e347a
BLAKE2b-256 checksum
How to use checksums
7618d250f816ed7976a6cebb9491239caea063ace7d1097d3ce4a42fb86fd85e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page