lib.rst 16 KB

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