Debian Codegraph @

mypyc/doc/librt.rst

raw
1 .. _librt:
2
3 Librt overview
4 ==============
5
6 The `librt <https://pypi.org/project/librt/>`__ package defines fast
7 primitive operations that are optimized for code compiled
8 using mypyc. It has carefully selected efficient alternatives for
9 certain Python standard library features.
10
11 ``librt`` is a small, focused library. The goal is not to reimplement
12 the Python standard library, but to address specific gaps or
13 bottlenecks.
14
15 Librt contents
16 --------------
17
18 Follow submodule links in the table to a detailed description of each submodule.
19
20 .. list-table::
21 :header-rows: 1
22 :widths: 30 70
23 :width: 100%
24
25 * - Module
26 - Description
27 * - :doc:`librt.base64 <librt_base64>`
28 - Fast Base64 encoding and decoding
29 * - :doc:`librt.random <librt_random>`
30 - Pseudorandom number generation
31 * - :doc:`librt.strings <librt_strings>`
32 - String and bytes utilities
33 * - :doc:`librt.threading <librt_threading>`
34 - Threading primitives
35 * - :doc:`librt.time <librt_time>`
36 - Time utilities
37 * - :doc:`librt.vecs <librt_vecs>`
38 - Fast growable array type ``vec``
39
40 Installing librt
41 ----------------
42
43 When you install mypy, it will also install a compatible version of librt as a
44 dependency. If you distribute compiled wheels or install compiled modules in
45 environments without mypy installed, install librt explicitly or depend on it
46 with a version constraint (but it's only needed if your code explicitly imports
47 ``librt``), e.g. ``python -m pip install librt>=X.Y``.
48
49 If you don't have a recent enough librt installed, importing librt will fail.
50 Compiled code often needs a version of librt that is not much older than the
51 mypyc being used.
52
53 Backward compatibility
54 ----------------------
55
56 We aim to keep librt backward compatible. It's recommended that you allow users
57 of your published projects that use librt to update to a more recent version. For
58 example, use a ``>=`` version constraint in your ``requirements.txt``.
59
60 Using librt in non-compiled code
61 --------------------------------
62
63 Using librt in code that is *not* compiled with mypyc is fully supported. However,
64 some librt features may have significantly degraded performance when used from
65 interpreted code. We will document the most notable such cases, but it's always
66 recommended to measure the performance impact when considering a switch from Python
67 standard library functionality to librt in a non-compiled use case.