lib.rst 16 KB

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