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.time <librt_time>`
34 - Time utilities
35 * - :doc:`librt.vecs <librt_vecs>`
36 - Fast growable array type ``vec``
37
38 Installing librt
39 ----------------
40
41 When you install mypy, it will also install a compatible version of librt as a
42 dependency. If you distribute compiled wheels or install compiled modules in
43 environments without mypy installed, install librt explicitly or depend on it
44 with a version constraint (but it's only needed if your code explicitly imports
45 ``librt``), e.g. ``python -m pip install librt>=X.Y``.
46
47 If you don't have a recent enough librt installed, importing librt will fail.
48 Compiled code often needs a version of librt that is not much older than the
49 mypyc being used.
50
51 Backward compatibility
52 ----------------------
53
54 We aim to keep librt backward compatible. It's recommended that you allow users
55 of your published projects that use librt to update to a more recent version. For
56 example, use a ``>=`` version constraint in your ``requirements.txt``.
57
58 Using librt in non-compiled code
59 --------------------------------
60
61 Using librt in code that is *not* compiled with mypyc is fully supported. However,
62 some librt features may have significantly degraded performance when used from
63 interpreted code. We will document the most notable such cases, but it's always
64 recommended to measure the performance impact when considering a switch from Python
65 standard library functionality to librt in a non-compiled use case.