Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tombulled/ua
User-Agent parsing and creation
https://github.com/tombulled/ua
ua user-agent
Last synced: 23 days ago
JSON representation
User-Agent parsing and creation
- Host: GitHub
- URL: https://github.com/tombulled/ua
- Owner: tombulled
- License: mit
- Created: 2021-04-14T06:59:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-11T20:23:46.000Z (almost 3 years ago)
- Last Synced: 2024-11-06T16:52:02.735Z (about 2 months ago)
- Topics: ua, user-agent
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ua
User-Agent parsing and creation## Installation
```console
pip install ua
```## Usage
```python
>>> import ua
```### Parsing
```python
>>> user_agent = ua.parse('Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0')
>>>
>>> user_agent
UserAgent(
products=[
Product(name='Mozilla', version='5.0', comments=['X11', 'Linux x86_64', 'rv:88.0']),
Product(name='Gecko', version='20100101', comments=[]),
Product(name='Firefox', version='88.0', comments=[])
]
)
>>>
>>> str(user_agent)
'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0'
```### Creation
```python
>>> user_agent = ua.UserAgent(
products=[
ua.Product(
name='SomeProduct',
version='1.0',
comments=['SomeComment']
)
]
)
>>>
>>> str(user_agent)
'SomeProduct/1.0 (SomeComment)'
```## References
* [User agent - Wikipedia](https://en.wikipedia.org/wiki/User_agent)
* [User-Agent - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent)
* [RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231#section-5.5.3)