lib.rst 17 KB

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