# Nim Standard Library

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Group by:
Source Edit

Author: | Andreas Rumpf
Version: | 2.0.8

Nim's library is divided into pure libraries, impure libraries, and wrappers.

Pure libraries do not depend on any external `*.dll` or `lib*.so` binary while impure libraries do. A wrapper is an impure library that is a very low-level interface to a C library.

Read this document for a quick overview of the API design.

# Nimble

Nim's standard library only covers the basics, check out https://nimble.directory/ for a list of 3rd party packages.

# Pure libraries

## Automatic imports

- system Basic procs and operators that every program needs. It also provides IO facilities for reading and writing text and binary files. It is imported implicitly by the compiler. Do not import it directly. It relies on compiler magic to work.

## Core

- atomics Types and operations for atomic operations and lockless algorithms.
- bitops Provides a series of low-level methods for bit manipulation.
- compilesettings Querying the compiler about diverse configuration settings from code.
- cpuinfo Procs to determine the number of CPUs / cores.
- effecttraits Access to the inferred .raises effects for Nim's macro system.
- endians Helpers that deal with different byte orders.
- locks Locks and condition variables for Nim.
- macrocache Provides an API for macros to collect compile-time information across modules.
- macros Contains the AST API and documentation of Nim for writing macros.
- rlocks Reentrant locks for Nim.
- typeinfo Provides (unsafe) access to Nim's run-time type information.
- typetraits Compile-time reflection procs for working with types.
- volatile Code for generating volatile loads and stores, which are useful in embedded and systems programming.

## Algorithms

- algorithm Some common generic algorithms like sort or binary search.
- enumutils Additional functionality for the built-in `enum` type.
- sequtils Operations for the built-in `seq` type which were inspired by functional programming languages.
- setutils Additional functionality for the built-in `set` type.

## Collections

- critbits A crit bit tree which is an efficient container for a sorted set of strings, or a sorted mapping of strings.
- deques Implementation of a double-ended queue. The underlying implementation uses a `seq`.
- heapqueue Implementation of a binary heap data structure that can be used as a priority queue.
- intsets Efficient implementation of a set of ints as a sparse bit set.
- lists Nim linked list support. Contains singly and doubly linked lists and circular lists ("rings").
- options The option type encapsulates an optional value.
- packedsets Efficient implementation of a set of ordinals as a sparse bit set.
- ropes A rope data type. Ropes can represent very long strings efficiently; in particular, concatenation is done in O(1) instead of O(n).
- sets Nim hash set support.
- strtabs The `strtabs` module implements an efficient hash table that is a mapping from strings to strings. Supports a case-sensitive, case-insensitive and style-insensitive modes.
- tables Nim hash table support. Contains tables, ordered tables, and count tables.

## String handling

- cstrutils Utilities for `cstring` handling.
- editdistance An algorithm to compute the edit distance between two Unicode strings.
- encodings Converts between different character encodings. On UNIX, this uses the `iconv` library, on Windows the Windows API.
- formatfloat Formatting floats as strings.
- objectdollar A generic `$` operator to convert objects to strings.
- punycode Implements a representation of Unicode with the limited ASCII character subset.
- strbasics Some high performance string operations.
- strformat Macro based standard string interpolation/formatting. Inspired by Python's f-strings. Note: if you need templating, consider using Nim Source Code Filters (SCF).
- strmisc Uncommon string handling operations that do not fit with the commonly used operations in strutils.
- strscans A `scanf` macro for convenient parsing of mini languages.
- strutils Common string handling operations like changing case of a string, splitting a string into substrings, searching for substrings, replacing substrings.
- unicode Support for handling the Unicode UTF-8 encoding.
- unidecode It provides a single proc that does Unicode to ASCII transliterations. Based on Python's Unidecode module.
- widestrs Nim support for C/C++'s wide strings.
- wordwrap An algorithm for word-wrapping Unicode strings.

## Time handling

- monotimes The `monotimes` module implements monotonic timestamps.
- times The `times` module contains support for working with time.

## Generic Operating System Services

- appdirs Helpers for determining special directories used by apps.
- cmdline System facilities for reading command line parameters.
- dirs Directory handling.
- distros Basics for OS distribution ("distro") detection and the OS's native package manager. Its primary purpose is to produce output for Nimble packages, but it also contains the widely used Distribution enum that is useful for writing platform-specific code. See packaging for hints on distributing Nim using OS packages.
- dynlib Accessing symbols from shared libraries.
- envvars Environment variable handling.
- exitprocs Adding hooks to program exit.
- files File handling.
- memfiles Support for memory-mapped files (Posix's `mmap`) on the different operating systems.
- os Basic operating system facilities like retrieving environment variables, reading command line arguments, working with directories, running shell commands, etc.
- oserrors OS error reporting.
- osproc Module for process communication beyond `os.execShellCmd`.
- paths Path handling.
- reservedmem Utilities for reserving portions of the address space of a program without consuming physical memory.
- streams A stream interface and two implementations thereof: the `FileStream` and the `StringStream` which implement the stream interface for Nim file objects (`File`) and strings. Other modules may provide other implementations for this standard stream interface.
- symlinks Symlink handling.
- syncio Various synchronized I/O operations.
- terminal A module to control the terminal output (also called console).
- tempfiles Some utilities for generating temporary path names and creating temporary files and directories.

## Math libraries

- complex Complex numbers and relevant mathematical operations.
- fenv Floating-point environment. Handling of floating-point rounding and exceptions (overflow, zero-divide, etc.).
- lenientops Binary operators for mixed integer/float expressions for convenience.
- math Mathematical operations like cosine, square root.
- random Fast and tiny random number generator.
- rationals Rational numbers and relevant mathematical operations.
- stats Statistical analysis.
- sysrand Cryptographically secure pseudorandom number generator.

## Internet Protocols and Support

- async Exports `asyncmacro` and `asyncfutures` for native backends, and `asyncjs` on the JS backend.
- asyncdispatch An asynchronous dispatcher for IO operations.
- asyncfile An asynchronous file reading and writing using `asyncdispatch`.
- asyncftpclient An asynchronous FTP client using the `asyncnet` module.
- asynchttpserver An asynchronous HTTP server using the `asyncnet` module.
- asyncmacro `async` and `multisync` macros for `asyncdispatch`.
- asyncnet Asynchronous sockets based on the `asyncdispatch` module.
- asyncstreams `FutureStream` - a future that acts as a queue.
- cgi Helpers for CGI applications.
- cookies Helper procs for parsing and generating cookies.
- httpclient A simple HTTP client with support for both synchronous and asynchronous retrieval of web pages.
- mimetypes A mimetypes database.
- nativesockets A low-level sockets API.
- net A high-level sockets API.
- selectors A selector API with backends specific to each OS. Supported OS primitives: `epoll`, `kqueue`, `poll`, and `select` on Windows.
- smtp A simple SMTP client with support for both synchronous and asynchronous operation.
- socketstreams An implementation of the streams interface for sockets.
- uri Functions for working with URIs and URLs.

## Threading

- isolation The `Isolated[T]` type for safe construction of isolated subgraphs that can be passed efficiently to different channels and threads.
- tasks Basic primitives for creating parallel programs.
- threadpool Implements Nim's spawn.
- typedthreads Basic Nim thread support.

## Parsers

- htmlparser HTML document parser that creates a XML tree representation.
- json High-performance JSON parser.
- lexbase A low-level module that implements an extremely efficient buffering scheme for lexers and parsers. This is used by the diverse parsing modules.
- parsecfg The `parsecfg` module implements a high-performance configuration file parser. The configuration file's syntax is similar to the Windows `.ini` format, but much more powerful, as it is not a line based parser. String literals, raw string literals, and triple quote string literals are supported as in the Nim programming language.
- parsecsv The `parsecsv` module implements a simple high-performance CSV parser.
- parsejson A JSON parser. It is used and exported by the json module, but can also be used in its own right.
- parseopt The `parseopt` module implements a command line option parser.
- parsesql The `parsesql` module implements a simple high-performance SQL parser.
- parseutils Helpers for parsing tokens, numbers, identifiers, etc.
- parsexml The `parsexml` module implements a simple high performance XML/HTML parser. The only encoding that is supported is UTF-8. The parser has been designed to be somewhat error-correcting, so that even some "wild HTML" found on the web can be parsed with it.
- pegs Procedures and operators for handling PEGs.

## Docutils

- packages/docutils/highlite Source highlighter for programming or markup languages. Currently, only a few languages are supported, other languages may be added. The interface supports one language nested in another.
- packages/docutils/rst A reStructuredText parser. A large subset is implemented. Some features of the markdown wiki syntax are also supported.
- packages/docutils/rstast An AST for the reStructuredText parser.
- packages/docutils/rstgen A generator of HTML/Latex from reStructuredText.

## XML Processing

- xmltree A simple XML tree. More efficient and simpler than the DOM. It also contains a macro for XML/HTML code generation.
- xmlparser XML document parser that creates a XML tree representation.

## Generators

- genasts AST generation using captured variables for macros.
- htmlgen A simple XML and HTML code generator. Each commonly used HTML tag has a corresponding macro that generates a string with its HTML representation.

## Hashing

- base64 A Base64 encoder and decoder.
- hashes Efficient computations of hash values for diverse Nim types.
- md5 The MD5 checksum algorithm.
- oids An OID is a global ID that consists of a timestamp, a unique counter, and a random value. This combination should suffice to produce a globally distributed unique ID.
- sha1 The SHA-1 checksum algorithm.

## Serialization

- jsonutils Hookable (de)serialization for arbitrary types using JSON.
- marshal Contains procs for serialization and deserialization of arbitrary Nim data structures.

## Miscellaneous

- assertions Assertion handling.
- browsers Procs for opening URLs with the user's default browser.
- colors Color handling.
- coro Experimental coroutines in Nim.
- decls Syntax sugar for some declarations.
- enumerate `enumerate` syntactic sugar based on Nim's macro system.
- importutils Utilities related to import and symbol resolution.
- logging A simple logger.
- segfaults Turns access violations or segfaults into a `NilAccessDefect` exception.
- sugar Nice syntactic sugar based on Nim's macro system.
- unittest Implements a Unit testing DSL.
- varints Decode variable-length integers that are compatible with SQLite.
- with The `with` macro for easy function chaining.
- wrapnils Allows evaluating expressions safely against nil dereferences.

## Modules for the JavaScript backend

- asyncjs Types and macros for writing asynchronous procedures in JavaScript.
- dom Declaration of the Document Object Model for the JS backend.
- jsbigints Arbitrary precision integers.
- jsconsole Wrapper for the `console` object.
- jscore The wrapper of core JavaScript functions. For most purposes, you should be using the `math`, `json`, and `times` stdlib modules instead of this module.
- jsfetch Wrapper for `fetch`.
- jsffi Types and macros for easier interaction with JavaScript.
- jsre Regular Expressions for the JavaScript target.

# Impure libraries

## Regular expressions

- re Procedures and operators for handling regular expressions. The current implementation uses PCRE.

- nre

  Many help functions for handling regular expressions. The current implementation uses PCRE.

## Database support

- db_mysql A higher level MySQL database wrapper. The same interface is implemented for other databases too.
- db_odbc A higher level ODBC database wrapper. The same interface is implemented for other databases too.
- db_postgres A higher level PostgreSQL database wrapper. The same interface is implemented for other databases too.
- db_sqlite A higher level SQLite database wrapper. The same interface is implemented for other databases too.

## Generic Operating System Services

- rdstdin Code for reading user input from stdin.

# Wrappers

The generated HTML for some of these wrappers is so huge that it is not contained in the distribution. You can then find them on the website.

## Windows-specific

- winlean Wrapper for a small subset of the Win32 API.
- registry Windows registry support.

## UNIX specific

- posix Wrapper for the POSIX standard.
- posix_utils Contains helpers for the POSIX standard or specialized for Linux and BSDs.

## Regular expressions

- pcre Wrapper for the PCRE library.

## Database support

- mysql Wrapper for the mySQL API.
- odbcsql interface to the ODBC driver.
- postgres Wrapper for the PostgreSQL API.
- sqlite3 Wrapper for the SQLite 3 API.

## Network Programming and Internet Protocols

- openssl Wrapper for OpenSSL.