Skip to content

Commit f2434ba

Browse files
committed
doc update, fixups
1 parent 3d5afdb commit f2434ba

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

README.rst

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,34 @@ Build Status
1010
.. image:: https://github.com/ua-parser/uap-python/actions/workflows/ci.yml/badge.svg
1111
:alt: CI on the master branch
1212

13-
⚠️ THIS IS NOT THE DOCUMENTATION YOU ARE LOOKING FOR (probably) ⚠️
14-
------------------------------------------------------------------
15-
16-
This is the readme for the `future 1.0 <https://github.com/ua-
17-
parser/uap-python/milestone/1>`_.
18-
19-
For the current releases, see `the 0.x branch
20-
<https://github.com/ua-parser/uap-python/tree/0.x#uap- python>`_.
21-
2213
Installing
2314
----------
2415

25-
Just add ``ua-parser`` to your project's dependencies, or run
16+
Add ``ua-parser[regex]`` to your project's dependencies, or run
2617

2718
.. code-block:: sh
2819
29-
$ pip install ua-parser
20+
$ pip install 'ua-parser[regex]'
3021
3122
to install in the current environment.
3223

33-
Installing `ua-parser-rs <https://pypi.org/project/ua-parser-rs>`_ or
34-
`google-re2 <https://pypi.org/project/google-re2/>`_ is *strongly*
35-
recommended as they yield *significantly* better performances. This
36-
can be done directly via the ``regex`` and ``re2`` optional
37-
dependencies respectively:
24+
ua-parser supports CPython 3.9 and newer, recent pypy (supporting
25+
3.10), and GraalPy 24.
3826

39-
.. code-block:: sh
27+
.. note::
28+
29+
The ``[regex]`` feature is *strongly* recommended:
4030

41-
$ pip install 'ua_parser[regex]'
42-
$ pip install 'ua_parser[re2]'
31+
- ``[re2]`` is slightly slower and only works with cpython, though
32+
it is still a great option then (and is more memory-efficient).
33+
- Pure python (no feature) is *significantly* slower, especially on
34+
non-cpython runtimes, but it is the most memory efficient even
35+
with caches.
4336

44-
If either dependency is already available (e.g. because the software
45-
makes use of re2 for other reasons) ``ua-parser`` will use the
46-
corresponding resolver automatically.
37+
See `builtin resolvers`_ for more explanation of the tradeoffs
38+
between the different options.
39+
40+
.. _builtin resolvers: https://readthedocs.org/ua-parser/uap-python/guides#builtin-resolvers
4741

4842
Quick Start
4943
-----------
@@ -109,3 +103,10 @@ Extract device information from user-agent string
109103
>>> ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
110104
>>> parse_device(ua_string)
111105
Device(family='Mac', brand='Apple', model='Mac')
106+
107+
Upgrading
108+
---------
109+
110+
Upgrading from 0.x? See `the upgrade guide`_.
111+
112+
.. _the upgrade guide: https://readthedocs.org/ua-parser/uap-python/advanced/migration

doc/advanced/migration.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ From 0.x to 1.0
55
Don't Touch A Thing
66
===================
77

8-
The first and simplest way to transition is to not transition: the 0.x
9-
API won't be removed for a long time, possibly ever. While it is
10-
unlikely to get updated any further and will eventually (hopefully?)
11-
fall behind, if you can't be arsed you probably don't have to until an
12-
unlikely 2.0.
8+
The first and simplest way to upgrade is to not do anything: the 0.x
9+
API is still present in 1.x and won't be removed for a long time,
10+
possibly ever.
11+
12+
While it is unlikely to get updated any further and will eventually
13+
(hopefully?) fall behind, if you can't be arsed you probably don't
14+
have to do anything for now, or just now.
1315

1416
Unavoidable Divergences
1517
=======================
@@ -29,20 +31,20 @@ special attention:
2931
# force initialisation of global parser
3032
ua_parser.parser
3133

32-
- The 1.0 API defaults to an :class:`re2-based parser
33-
<ua_parser.re2.Resolver>` if |re2|_ is installed, although it seems
34-
unlikely you may wish to consider replacing it with configuring a
35-
:class:`~ua_parser.Parser` with a :class:`ua_parser.basic.Resolver`
36-
if |re2|_ is one of your dependencies.
34+
- The 1.0 API defaults to powerful native parsers (based on |regex|_
35+
or |re2|_) if available, although it seems unlikely you may wish to
36+
consider replacing it with configuring a :class:`~ua_parser.Parser`
37+
with a :class:`ua_parser.basic.Resolver`, especially if for some
38+
reason |re2| is already one of your dependencies but you want to
39+
*avoid* the |re2|-based resolver.
3740

3841
Default Ruleset
3942
===============
4043

4144
While the 1.0 API was designed to better respect :pep:`8` and support
42-
:mod:`typing`, it was also designed to easily be transitioned from.
45+
:mod:`typing`, it was also designed to easily be transitioned to.
4346

44-
Given a 0.x API not using YAML, the conversion should be very easy and
45-
consists of:
47+
Given a 0.x API not using YAML, the conversion consists of:
4648

4749
- updating the import from ``ua_parser.user_agent_parser`` to just
4850
``ua_parser``
@@ -116,7 +118,7 @@ Legacy YAML support can be added via a pretty small shim::
116118
import ua_parser
117119
from ua_parser.loaders import load_yaml
118120

119-
if yaml_path = os.environ.get("UA_PARSER_YAML"):
121+
if yaml_path := os.environ.get("UA_PARSER_YAML"):
120122
ua_parser.parser = ua_parser.Parser.from_matchers(
121123
load_yaml(yaml_path))
122124

doc/guides.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ Guides
77
Custom Rulesets
88
===============
99

10-
ua-parser defaults to the version of `ua-core
11-
<https://github.com/ua-parser/uap-core/blob/master/regexes.yaml>`_
12-
current when it was packaged, using a precompiled version of
13-
``regexes.yaml``.
10+
ua-parser defaults to the latest stable release of `ua-core`_ via
11+
`precompiled regexes.yaml`__.
1412

1513
That is a suitable defaut, but there are plenty of reasons to use
1614
custom rulesets:
1715

1816
- trim down the default ruleset to only the most current or relevant
1917
rules for efficiency e.g. you might not care about CalDav or podcast
2018
applications
21-
- add new rules relevant to your own traffic but which don't (possibly
22-
can't) be in the main project
19+
- add new rules relevant to your own traffic but which aren't (possibly
20+
can't be) in the main project
2321
- experiment with the creation of new rules
2422
- use a completely bespoke ruleset to track UA-identified API clients
23+
- use "experimental" rules which haven't been released yet (although
24+
`ua-parser-builtins`_ provides regular prerelease versions which may
25+
be suitable for this)
2526

2627
ua-parser provides easy ways to load custom rolesets:
2728

@@ -38,6 +39,12 @@ ua-parser provides easy ways to load custom rolesets:
3839
parser = Parser.from_matchers(load_yaml("regexes.yaml"))
3940
parser.parse(some_ua)
4041
42+
.. _ua-parser-builtins: https://pypi.org/project/ua-parser-builtins
43+
44+
__ ua-parser-builtins_
45+
46+
.. _ua-core: https://github.com/ua-parser/uap-core/blob/master/regexes.yaml
47+
4148
.. _guide-custom-global-parser:
4249

4350
Custom Global Parser
@@ -129,6 +136,8 @@ from here on::
129136
:class:`~ua_parser.caching.Local`, which is also caching-related,
130137
and serves to use thread-local caches rather than a shared cache.
131138

139+
.. _builtin-resolvers:
140+
132141
Builtin Resolvers
133142
=================
134143

@@ -207,9 +216,9 @@ If available, it is the second-preferred resolver, without a cache.
207216
The ``basic`` resolver is a naive linear traversal of all rules, using
208217
the standard library's ``re``. It:
209218

210-
- Is *extremely* slow, about 10x slower than ``re2`` in cpython, and
219+
- Is *extremely* slow: about 10x slower than ``re2`` on cpython, and
211220
pypy and graal's regex implementations do *not* like the workload
212-
and behind cpython by a factor of 3~4.
221+
and are 3x-4x slower than *cpython*.
213222
- Has perfect compatibility, with the caveat above, by virtue of being
214223
built entirely out of standard library code.
215224
- Is basically as safe as Python software can be by virtue of being

doc/installation.rst

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,11 @@
22
Installation
33
============
44

5-
Python Version
6-
==============
7-
8-
ua-parser currently supports CPython 3.9 and newer, recent Pypy
9-
(supporting 3.10), and Graal 24.
10-
11-
.. note::
12-
13-
While pypy and graal are supported, they are rather slow when using
14-
pure python mode and ``[re2]`` is not supported, so using the
15-
``[regex]`` feature is very strongly recommended.
16-
175
Installation
186
============
197

208
.. include:: ../README.rst
21-
:start-line: 23
9+
:start-line: 14
2210
:end-before: Quick Start
2311

2412
Optional Dependencies
@@ -35,9 +23,9 @@ if installed, but can also be installed via and alongside ua-parser:
3523
$ pip install 'ua-parser[yaml]'
3624
$ pip install 'ua-parser[regex,yaml]'
3725
38-
``yaml`` simply enables the ability to :func:`load yaml rulesets
26+
``yaml`` enables the ability to :func:`load rulesets from yaml
3927
<ua_parser.loaders.load_yaml>`.
4028

41-
The other two dependencies enable more efficient resolvers. By
42-
default, ``ua-parser`` will select the fastest resolver it finds out
43-
of the available set. For more, see :ref:`builtin resolvers`.
29+
The other two features enable more efficient resolvers. By default,
30+
``ua-parser`` will select the fastest resolver it finds out of the
31+
available set (regex > re2 > python).

doc/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Quick Start
33
===========
44

55
.. include:: ../README.rst
6-
:start-line: 47
6+
:start-line: 44

0 commit comments

Comments
 (0)