lib.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. ====================
  2. Nim Standard Library
  3. ====================
  4. :Author: Andreas Rumpf
  5. :Version: |nimversion|
  6. .. contents::
  7. Nim's library is divided into *pure libraries*, *impure libraries* and *wrappers*.
  8. Pure libraries do not depend on any external ``*.dll`` or ``lib*.so`` binary
  9. while impure libraries do. A wrapper is an impure library that is a very
  10. low-level interface to a C library.
  11. Read this `document <apis.html>`_ for a quick overview of the API design.
  12. Nimble
  13. ======
  14. Nim's standard library only covers the basics, check
  15. out `<https://nimble.directory/>`_ for a list of 3rd party packages.
  16. Pure libraries
  17. ==============
  18. Automatic imports
  19. -----------------
  20. * `system <system.html>`_
  21. Basic procs and operators that every program needs. It also provides IO
  22. facilities for reading and writing text and binary files. It is imported
  23. implicitly by the compiler. Do not import it directly. It relies on compiler
  24. magic to work.
  25. * `threads <threads.html>`_
  26. Basic Nim thread support. **Note**: This is part of the system module. Do not
  27. import it explicitly. Enabled with ``--threads:on``.
  28. * `channels <channels.html>`_
  29. Nim message passing support for threads. **Note**: This is part of the
  30. system module. Do not import it explicitly. Enabled with ``--threads:on``.
  31. Core
  32. ----
  33. * `bitops <bitops.html>`_
  34. Provides a series of low level methods for bit manipulation.
  35. * `cpuinfo <cpuinfo.html>`_
  36. This module implements procs to determine the number of CPUs / cores.
  37. * `endians <endians.html>`_
  38. This module contains helpers that deal with different byte orders.
  39. * `lenientops <lenientops.html>`_
  40. Provides binary operators for mixed integer/float expressions for convenience.
  41. * `locks <locks.html>`_
  42. Locks and condition variables for Nim.
  43. * `macros <macros.html>`_
  44. Contains the AST API and documentation of Nim for writing macros.
  45. * `rlocks <rlocks.html>`_
  46. Reentrant locks for Nim.
  47. * `typeinfo <typeinfo.html>`_
  48. Provides (unsafe) access to Nim's run time type information.
  49. * `typetraits <typetraits.html>`_
  50. This module defines compile-time reflection procs for working with types.
  51. * `volatile <volatile.html>`_
  52. This module contains code for generating volatile loads and stores,
  53. which are useful in embedded and systems programming.
  54. Algorithms
  55. ----------
  56. * `algorithm <algorithm.html>`_
  57. Implements some common generic algorithms like sort or binary search.
  58. * `sequtils <sequtils.html>`_
  59. This module implements operations for the built-in seq type
  60. which were inspired by functional programming languages.
  61. Collections
  62. -----------
  63. * `critbits <critbits.html>`_
  64. This module implements a *crit bit tree* which is an efficient
  65. container for a sorted set of strings, or for a sorted mapping of strings.
  66. * `deques <deques.html>`_
  67. Implementation of a double-ended queue.
  68. The underlying implementation uses a ``seq``.
  69. * `heapqueue <heapqueue.html>`_
  70. Implementation of a heap data structure that can be used as a priority queue.
  71. * `intsets <intsets.html>`_
  72. Efficient implementation of a set of ints as a sparse bit set.
  73. * `lists <lists.html>`_
  74. Nim linked list support. Contains singly and doubly linked lists and
  75. circular lists ("rings").
  76. * `options <options.html>`_
  77. The option type encapsulates an optional value.
  78. * `sets <sets.html>`_
  79. Nim hash and bit set support.
  80. * `sharedlist <sharedlist.html>`_
  81. Nim shared linked list support. Contains shared singly linked list.
  82. * `sharedtables <sharedtables.html>`_
  83. Nim shared hash table support. Contains shared tables.
  84. * `tables <tables.html>`_
  85. Nim hash table support. Contains tables, ordered tables and count tables.
  86. String handling
  87. ---------------
  88. * `cstrutils <cstrutils.html>`_
  89. Utilities for ``cstring`` handling.
  90. * `std/editdistance <editdistance.html>`_
  91. This module contains an algorithm to compute the edit distance between two
  92. Unicode strings.
  93. * `encodings <encodings.html>`_
  94. Converts between different character encodings. On UNIX, this uses
  95. the ``iconv`` library, on Windows the Windows API.
  96. * `parseutils <parseutils.html>`_
  97. This module contains helpers for parsing tokens, numbers, identifiers, etc.
  98. * `pegs <pegs.html>`_
  99. This module contains procedures and operators for handling PEGs.
  100. * `punycode <punycode.html>`_
  101. Implements a representation of Unicode with the limited ASCII character subset.
  102. * `ropes <ropes.html>`_
  103. This module contains support for a *rope* data type.
  104. Ropes can represent very long strings efficiently; especially concatenation
  105. is done in O(1) instead of O(n).
  106. * `strformat <strformat.html>`_
  107. Macro based standard string interpolation / formatting. Inspired by
  108. Python's ``f``-strings.
  109. * `strmisc <strmisc.html>`_
  110. This module contains uncommon string handling operations that do not
  111. fit with the commonly used operations in strutils.
  112. * `strscans <strscans.html>`_
  113. This module contains a ``scanf`` macro for convenient parsing of mini languages.
  114. * `strtabs <strtabs.html>`_
  115. The ``strtabs`` module implements an efficient hash table that is a mapping
  116. from strings to strings. Supports a case-sensitive, case-insensitive and
  117. style-insensitive modes.
  118. * `strutils <strutils.html>`_
  119. This module contains common string handling operations like changing
  120. case of a string, splitting a string into substrings, searching for
  121. substrings, replacing substrings.
  122. * `unicode <unicode.html>`_
  123. This module provides support to handle the Unicode UTF-8 encoding.
  124. * `unidecode <unidecode.html>`_
  125. It provides a single proc that does Unicode to ASCII transliterations.
  126. Based on Python's Unidecode module.
  127. * `std/wordwrap <wordwrap.html>`_
  128. This module contains an algorithm to wordwrap a Unicode string.
  129. Time handling
  130. -------------
  131. * `std/monotimes <monotimes.html>`_
  132. The `monotimes` module implements monotonic timestamps.
  133. * `times <times.html>`_
  134. The ``times`` module contains support for working with time.
  135. Generic Operating System Services
  136. ---------------------------------
  137. * `distros <distros.html>`_
  138. This module implements the basics for OS distribution ("distro") detection
  139. and the OS's native package manager.
  140. Its primary purpose is to produce output for Nimble packages,
  141. but it also contains the widely used **Distribution** enum
  142. that is useful for writing platform specific code.
  143. See `packaging <packaging.html>`_ for hints on distributing Nim using OS packages.
  144. * `dynlib <dynlib.html>`_
  145. This module implements the ability to access symbols from shared libraries.
  146. * `marshal <marshal.html>`_
  147. Contains procs for serialization and deseralization of arbitrary Nim
  148. data structures.
  149. * `memfiles <memfiles.html>`_
  150. This module provides support for memory mapped files (Posix's ``mmap``)
  151. on the different operating systems.
  152. * `os <os.html>`_
  153. Basic operating system facilities like retrieving environment variables,
  154. reading command line arguments, working with directories, running shell
  155. commands, etc.
  156. * `osproc <osproc.html>`_
  157. Module for process communication beyond ``os.execShellCmd``.
  158. * `streams <streams.html>`_
  159. This module provides a stream interface and two implementations thereof:
  160. the `FileStream` and the `StringStream` which implement the stream
  161. interface for Nim file objects (`File`) and strings. Other modules
  162. may provide other implementations for this standard stream interface.
  163. * `terminal <terminal.html>`_
  164. This module contains a few procedures to control the *terminal*
  165. (also called *console*). The implementation simply uses ANSI escape
  166. sequences and does not depend on any other module.
  167. Math libraries
  168. --------------
  169. * `complex <complex.html>`_
  170. This module implements complex numbers and their mathematical operations.
  171. * `fenv <fenv.html>`_
  172. Floating-point environment. Handling of floating-point rounding and
  173. exceptions (overflow, zero-divide, etc.).
  174. * `math <math.html>`_
  175. Mathematical operations like cosine, square root.
  176. * `mersenne <mersenne.html>`_
  177. Mersenne twister random number generator.
  178. * `random <random.html>`_
  179. Fast and tiny random number generator.
  180. * `rationals <rationals.html>`_
  181. This module implements rational numbers and their mathematical operations.
  182. * `stats <stats.html>`_
  183. Statistical analysis
  184. * `std/sums <sums.html>`_
  185. Fast sumation functions.
  186. Internet Protocols and Support
  187. ------------------------------
  188. * `asyncdispatch <asyncdispatch.html>`_
  189. This module implements an asynchronous dispatcher for IO operations.
  190. * `asyncfile <asyncfile.html>`_
  191. This module implements asynchronous file reading and writing using
  192. ``asyncdispatch``.
  193. * `asyncftpclient <asyncftpclient.html>`_
  194. This module implements an asynchronous FTP client using the ``asyncnet``
  195. module.
  196. * `asynchttpserver <asynchttpserver.html>`_
  197. This module implements an asynchronous HTTP server using the ``asyncnet``
  198. module.
  199. * `asyncnet <asyncnet.html>`_
  200. This module implements asynchronous sockets based on the ``asyncdispatch``
  201. module.
  202. * `asyncstreams <asyncstreams.html>`_
  203. This module provides `FutureStream` - a future that acts as a queue.
  204. * `cgi <cgi.html>`_
  205. This module implements helpers for CGI applications.
  206. * `cookies <cookies.html>`_
  207. This module contains helper procs for parsing and generating cookies.
  208. * `httpclient <httpclient.html>`_
  209. This module implements a simple HTTP client which supports both synchronous
  210. and asynchronous retrieval of web pages.
  211. * `mimetypes <mimetypes.html>`_
  212. This module implements a mimetypes database.
  213. * `nativesockets <nativesockets.html>`_
  214. This module implements a low-level sockets API.
  215. * `net <net.html>`_
  216. This module implements a high-level sockets API. It replaces the
  217. ``sockets`` module.
  218. * `selectors <selectors.html>`_
  219. This module implements a selector API with backends specific to each OS.
  220. Currently epoll on Linux and select on other operating systems.
  221. * `smtp <smtp.html>`_
  222. This module implement a simple SMTP client.
  223. * `uri <uri.html>`_
  224. This module provides functions for working with URIs.
  225. Threading
  226. ---------
  227. * `threadpool <threadpool.html>`_
  228. Implements Nim's `spawn <manual_experimental.html#parallel-amp-spawn>`_.
  229. Parsers
  230. -------
  231. * `htmlparser <htmlparser.html>`_
  232. This module parses an HTML document and creates its XML tree representation.
  233. * `json <json.html>`_
  234. High performance JSON parser.
  235. * `lexbase <lexbase.html>`_
  236. This is a low level module that implements an extremely efficient buffering
  237. scheme for lexers and parsers. This is used by the diverse parsing modules.
  238. * `parsecfg <parsecfg.html>`_
  239. The ``parsecfg`` module implements a high performance configuration file
  240. parser. The configuration file's syntax is similar to the Windows ``.ini``
  241. format, but much more powerful, as it is not a line based parser. String
  242. literals, raw string literals and triple quote string literals are supported
  243. as in the Nim programming language.
  244. * `parsecsv <parsecsv.html>`_
  245. The ``parsecsv`` module implements a simple high performance CSV parser.
  246. * `parseopt <parseopt.html>`_
  247. The ``parseopt`` module implements a command line option parser.
  248. * `parsesql <parsesql.html>`_
  249. The ``parsesql`` module implements a simple high performance SQL parser.
  250. * `parsexml <parsexml.html>`_
  251. The ``parsexml`` module implements a simple high performance XML/HTML parser.
  252. The only encoding that is supported is UTF-8. The parser has been designed
  253. to be somewhat error correcting, so that even some "wild HTML" found on the
  254. Web can be parsed with it.
  255. Docutils
  256. --------
  257. * `packages/docutils/highlite <highlite.html>`_
  258. Source highlighter for programming or markup languages. Currently
  259. only few languages are supported, other languages may be added.
  260. The interface supports one language nested in another.
  261. * `packages/docutils/rst <rst.html>`_
  262. This module implements a reStructuredText parser. A large subset
  263. is implemented. Some features of the markdown wiki syntax are
  264. also supported.
  265. * `packages/docutils/rstast <rstast.html>`_
  266. This module implements an AST for the reStructuredText parser.
  267. * `packages/docutils/rstgen <rstgen.html>`_
  268. This module implements a generator of HTML/Latex from reStructuredText.
  269. XML Processing
  270. --------------
  271. * `xmltree <xmltree.html>`_
  272. A simple XML tree. More efficient and simpler than the DOM. It also
  273. contains a macro for XML/HTML code generation.
  274. * `xmlparser <xmlparser.html>`_
  275. This module parses an XML document and creates its XML tree representation.
  276. Generators
  277. ----------
  278. * `htmlgen <htmlgen.html>`_
  279. This module implements a simple XML and HTML code
  280. generator. Each commonly used HTML tag has a corresponding macro
  281. that generates a string with its HTML representation.
  282. Hashing
  283. -------
  284. * `base64 <base64.html>`_
  285. This module implements a base64 encoder and decoder.
  286. * `hashes <hashes.html>`_
  287. This module implements efficient computations of hash values for diverse
  288. Nim types.
  289. * `md5 <md5.html>`_
  290. This module implements the MD5 checksum algorithm.
  291. * `oids <oids.html>`_
  292. An OID is a global ID that consists of a timestamp,
  293. a unique counter and a random value. This combination should suffice to
  294. produce a globally distributed unique ID. This implementation was extracted
  295. from the Mongodb interface and it thus binary compatible with a Mongo OID.
  296. * `std/sha1 <sha1.html>`_
  297. This module implements a sha1 encoder and decoder.
  298. Miscellaneous
  299. -------------
  300. * `browsers <browsers.html>`_
  301. This module implements procs for opening URLs with the user's default
  302. browser.
  303. * `colors <colors.html>`_
  304. This module implements color handling for Nim.
  305. * `coro <coro.html>`_
  306. This module implements experimental coroutines in Nim.
  307. * `logging <logging.html>`_
  308. This module implements a simple logger.
  309. * `segfaults <segfaults.html>`_
  310. Turns access violations or segfaults into a ``NilAccessError`` exception.
  311. * `sugar <sugar.html>`_
  312. This module implements nice syntactic sugar based on Nim's macro system.
  313. * `unittest <unittest.html>`_
  314. Implements a Unit testing DSL.
  315. * `std/varints <varints.html>`_
  316. Decode variable length integers that are compatible with SQLite.
  317. Modules for JS backend
  318. ----------------------
  319. * `asyncjs <asyncjs.html>`_
  320. Types and macros for writing asynchronous procedures in JavaScript.
  321. * `dom <dom.html>`_
  322. Declaration of the Document Object Model for the JS backend.
  323. * `jsconsole <jsconsole.html>`_
  324. Wrapper for the ``console`` object.
  325. * `jscore <jscore.html>`_
  326. Wrapper of core JavaScript functions. For most purposes you should be using
  327. the ``math``, ``json``, and ``times`` stdlib modules instead of this module.
  328. * `jsffi <jsffi.html>`_
  329. Types and macros for easier interaction with JavaScript.
  330. Impure libraries
  331. ================
  332. Regular expressions
  333. -------------------
  334. * `re <re.html>`_
  335. This module contains procedures and operators for handling regular
  336. expressions. The current implementation uses PCRE.
  337. Database support
  338. ----------------
  339. * `db_postgres <db_postgres.html>`_
  340. A higher level PostgreSQL database wrapper. The same interface is implemented
  341. for other databases too.
  342. * `db_mysql <db_mysql.html>`_
  343. A higher level MySQL database wrapper. The same interface is implemented
  344. for other databases too.
  345. * `db_sqlite <db_sqlite.html>`_
  346. A higher level SQLite database wrapper. The same interface is implemented
  347. for other databases too.
  348. Wrappers
  349. ========
  350. The generated HTML for some of these wrappers is so huge that it is
  351. not contained in the distribution. You can then find them on the website.
  352. Windows specific
  353. ----------------
  354. * `winlean <winlean.html>`_
  355. Contains a wrapper for a small subset of the Win32 API.
  356. * `registry <registry.html>`_
  357. Windows registry support.
  358. UNIX specific
  359. -------------
  360. * `posix <posix.html>`_
  361. Contains a wrapper for the POSIX standard.
  362. * `posix_utils <posix_utils.html>`_
  363. Contains helpers for the POSIX standard or specialized for Linux and BSDs.
  364. Regular expressions
  365. -------------------
  366. * `pcre <pcre.html>`_
  367. Wrapper for the PCRE library.
  368. GUI libraries
  369. -------------
  370. * `iup <iup.html>`_
  371. Wrapper of the IUP GUI library.
  372. Database support
  373. ----------------
  374. * `postgres <postgres.html>`_
  375. Contains a wrapper for the PostgreSQL API.
  376. * `mysql <mysql.html>`_
  377. Contains a wrapper for the mySQL API.
  378. * `sqlite3 <sqlite3.html>`_
  379. Contains a wrapper for SQLite 3 API.
  380. * `odbcsql <odbcsql.html>`_
  381. interface to the ODBC driver.
  382. Network Programming and Internet Protocols
  383. ------------------------------------------
  384. * `openssl <openssl.html>`_
  385. Wrapper for OpenSSL.