stdlib.rst 5.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
MicroPython Standard Library
============================
Pycardium contains some modules from the MicroPython standard library.  These
are:

.. py:module:: ubinascii

``ubinascii``
-------------
Refer to the official `MicroPython docs for ubinascii`_.

.. _MicroPython docs for ubinascii: http://docs.micropython.org/en/latest/library/ubinascii.html

.. py:module:: ucollections

``ucollections``
----------------

.. py:function:: namedtuple(...)

   See the official `MicroPython docs for namedtuple`_ for details.

   .. _MicroPython docs for namedtuple: http://docs.micropython.org/en/latest/library/ucollections.html#ucollections.namedtuple

.. py:module:: uerrno

``uerrno``
----------
Refer to the offical `MicroPython docs for uerrno`_.

.. _MicroPython docs for uerrno: http://docs.micropython.org/en/latest/library/uerrno.html

.. py:module:: uheapq

``uheapq``
----------
Refer to the offical `MicroPython docs for uheapq`_.

.. _MicroPython docs for uheapq: http://docs.micropython.org/en/latest/library/uheapq.html

.. py:module:: uio

``uio``
-------
Refer to the offical `MicroPython docs for uio`_.

.. _MicroPython docs for uio: http://docs.micropython.org/en/latest/library/uio.html

.. py:module:: ujson

``ujson``
---------
Refer to the offical `MicroPython docs for ujson`_.

.. _MicroPython docs for ujson: http://docs.micropython.org/en/latest/library/ujson.html

.. py:module:: urandom

``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)
   :noindex:

   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
   ways.

.. 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

``ure``
-------
Minimal regular expression library.  Refer to the offical `MicroPython docs for ure`_.

.. _MicroPython docs for ure: http://docs.micropython.org/en/latest/library/ure.html

.. py:module:: ustruct

``ustruct``
-----------
Refer to the offical `MicroPython docs for ustruct`_.

.. _MicroPython docs for ustruct: http://docs.micropython.org/en/latest/library/ustruct.html

``utime``
---------
``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: https://github.com/micropython/micropython-lib

.. py:module:: collections

``collections``
---------------
Collections module.

.. py:module:: contextlib

``contextlib``
--------------
Contextlib module.

.. py:module:: functools

``functools``
-------------
Functools module.

.. py:module:: itertools

``itertools``
-------------
Itertools module.

.. warning::

   :py:func:`itertools.tee` is not implemented correctly.

.. py:module:: string

``string``
----------
String module.

.. py:module:: struct

``struct``
----------
Struct module.

.. py:module:: uuid

``uuid``
--------

185
.. py:class:: UUID(hex=None, bytes=None, int=None, version=None)
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203

   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``.

   **Examples**:

   .. code-block:: python

      UUID('{12345678-1234-5678-1234-567812345678}')
      UUID('12345678123456781234567812345678')
      UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
      UUID(bytes='\x12\x34\x56\x78' * 4)
      UUID(int=0x12345678123456781234567812345678)

Rahix's avatar
Rahix committed
204 205
   .. versionadded:: 1.10

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
   .. 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

222
.. py:function:: uuid4():
223 224 225

   Generate a new UUID version 4 (random UUID).

Rahix's avatar
Rahix committed
226
   .. versionadded:: 1.10