Verified Commit 621140f4 authored by Rahix's avatar Rahix
Browse files

docs(pycardium): Document python standard library

Add docs about the included modules from MicroPython and CPython stdlib.
Signed-off-by: Rahix's avatarRahix <>
parent b0348430
......@@ -21,6 +21,7 @@ Last but not least, if you want to start hacking the lower-level firmware, the
:caption: Pycardium
MicroPython Standard Library
Pycardium contains some modules from the MicroPython standard library. These
.. py:module:: ubinascii
Refer to the official `MicroPython docs for ubinascii`_.
.. _MicroPython docs for ubinascii:
.. py:module:: ucollections
.. py:function:: namedtuple(...)
See the official `MicroPython docs for namedtuple`_ for details.
.. _MicroPython docs for namedtuple:
.. py:module:: uerrno
Refer to the offical `MicroPython docs for uerrno`_.
.. _MicroPython docs for uerrno:
.. py:module:: uheapq
Refer to the offical `MicroPython docs for uheapq`_.
.. _MicroPython docs for uheapq:
.. py:module:: uio
Refer to the offical `MicroPython docs for uio`_.
.. _MicroPython docs for uio:
.. py:module:: ujson
Refer to the offical `MicroPython docs for ujson`_.
.. _MicroPython docs for ujson:
.. py:module:: urandom
Pseudo-random number generator.
.. py:function:: choice(seq)
Return a random element from the non-empty sequence ``seq``.
.. py:function:: getrandbits(k)
Returns a Python integer with ``k`` random bits.
.. py:function:: randint(a, b)
Return a random integer ``N`` such that ``a <= N <= b``. Alias for
:py:func:`randrange(a, b+1) <urandom.randrange>`.
.. py:function:: random()
Return the next random floating point number in the range [0.0, 1.0).
.. py:function:: randrange(start, stop, [step])
.. py:function:: randrange(stop)
Return a randomly selected element from ``range(start, stop, step)``. This
is equivalent to ``urandom.choice(range(start, stop, step))``, but doesn’t
actually build a range object.
The positional argument pattern matches that of ``range()``. Keyword
arguments should not be used because the function may use them in unexpected
.. py:function:: seed(n)
Seed the pseudo-random number generator from ``n``.
.. note::
CPython does not provide a :py:func:`seed` function. This is a
difference in the MicroPython implementation.
.. py:function:: uniform(a, b)
Return a random floating point number ``N`` such that ``a <= N <= b`` for
``a <= b`` and ``b <= N <= a`` for ``b < a``.
The end-point value ``b`` may or may not be included in the range depending
on floating-point rounding in the equation ``a + (b-a) * random()``.
.. py:module:: ure
Minimal regular expression library. Refer to the offical `MicroPython docs for ure`_.
.. _MicroPython docs for ure:
.. py:module:: ustruct
Refer to the offical `MicroPython docs for ustruct`_.
.. _MicroPython docs for ustruct:
``utime`` contains non-standard functions as well. Please refer to our
dedicated :py:mod:`utime` docs.
Python Standard Library
Additionally to the MicroPython module, Pycardium contains a subset of the
CPython standard library, as implemented by `micropython-lib`_. The following
modules are included:
.. _micropython-lib:
.. py:module:: collections
Collections module.
.. py:module:: contextlib
Contextlib module.
.. py:module:: functools
Functools module.
.. py:module:: itertools
Itertools module.
.. warning::
:py:func:`itertools.tee` is not implemented correctly.
.. py:module:: string
String module.
.. py:module:: struct
Struct module.
.. py:module:: uuid
.. py:class:: uuid.UUID(hex=None, bytes=None, int=None, version=None)
Create a new UUID object.
Exactly one of ``hex``, ``bytes``, or ``int`` must be given. The
``version`` argument is optional; if given, the resulting UUID will have its
variant and version set according to RFC 4122, overriding the given ``hex``,
``bytes``, or ``int``.
.. code-block:: python
UUID(bytes='\x12\x34\x56\x78' * 4)
.. py:attribute:: bytes
UUID as ``bytes()`` object
.. py:attribute:: node
Node of this UUID
.. py:attribute:: hex
Hex-String representation of this UUID
.. py:attribute:: version
UUID version accordiung to RFC 4122
.. py:function:: uuid.uuid4():
Generate a new UUID version 4 (random UUID).
.. todo::
This function is not yet usable because we don't have
:py:func:`os.urandom` yet.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment