crystal
1.21.0 / published Aug 13, 2026 / repository
The Crystal standard library
Crystal
Crystal is a programming language with the following goals:
- Have a syntax similar to Ruby (but compatibility with it is not a goal)
- Statically type-checked but without having to specify the type of variables or method arguments.
- Be able to call C code by writing bindings to it in Crystal.
- Have compile-time evaluation and generation of code, to avoid boilerplate code.
- Compile to efficient native code.
Why?
We love Ruby's efficiency for writing code.
We love C's efficiency for running code.
We want the best of both worlds.
We want the compiler to understand what we mean without having to specify types everywhere.
We want full OOP.
Oh, and we don't want to write C code to make the code run faster.
Project Status
Within a major version, language features won't be removed or changed in any way that could prevent a Crystal program written with that version from compiling and working. The built-in standard library might be enriched, but it will always be done with backwards compatibility in mind.
Development of the Crystal language is possible thanks to the community's effort and the continued support of 84codes and every other sponsor.
Installing
Follow these installation instructions
Try it online
Documentation
Community
Have any questions or suggestions? Ask on the Crystal Forum, on our Gitter channel or IRC channel #crystal-lang at irc.libera.chat, or on Stack Overflow under the crystal-lang tag. There is also an archived Google Group.
Contributing
The Crystal repository is hosted at crystal-lang/crystal on GitHub.
Read the general Contributing guide, and then:
- Fork it (https://github.com/crystal-lang/crystal/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
API
- ArgumentError
Raised when the arguments are wrong and there isn't a more specific
Exceptionclass. - Array(T)
An
Arrayis an ordered, integer-indexed collection of objects of type T. - Atomic(T)
A value that may be updated atomically.
- Base64
The
Base64module provides for the encoding (#encode,#strict_encode,#urlsafe_encode) and decoding (#decode) of binary data using a base64 representation. - Benchmark
The Benchmark module provides methods for benchmarking Crystal code, giving detailed reports on the time and memory taken for each task.
- BigDecimal
A
BigDecimalcan represent arbitrarily large precision decimals. - BigFloat
A
BigFloatcan represent arbitrarily large floats. - BigInt
A
BigIntcan represent arbitrarily large integers. - BigRational
Rational numbers are represented as the quotient of arbitrarily large numerators and denominators.
- BitArray
BitArrayis an array data structure that compactly stores bits. - Bool
Bool has only two possible values:
trueandfalse. - Box(T)
A Box allows turning any object to a
Void*and back. - Bytes
- CSV
Provides methods and classes for parsing and generating CSV (comma-separated values) strings.
- Channel(T)
A
Channelenables concurrent communication between fibers. - Char
A
Charrepresents a Unicode code point. - Class
- Colorize
With
Colorizeyou can change the fore- and background colors and text decorations when rendering text on terminals supporting ANSI escape codes. - Comparable(T)
The
Comparablemixin is used by classes whose objects may be ordered. - Complex
A complex number is a number represented in the form a + bi.
- Compress
- Crypto
- Crystal
- Deprecated
This annotation marks features as deprecated.
- Deque(T)
A Deque ("double-ended queue") is a collection of objects of type T that behaves much like an Array.
- Digest
Digestis the base type of hashing algorithms likeDigest::MD5,Digest::SHA1,Digest::SHA256, orDigest::SHA512. - Dir
Objects of class
Dirare directory streams representing directories in the underlying file system. - DivisionByZeroError
Raised when attempting to divide an integer by 0.
- ECR
Embedded Crystal (ECR) is a template language for embedding Crystal code into other text, that includes but is not limited to HTML.
- ENV
ENVis a hash-like accessor for environment variables. - Enum
Enum is the base type of all enums.
- Enumerable(T)
The
Enumerablemixin provides collection classes with several traversal, searching, filtering and querying methods. - Errno
Errno wraps and gives access to libc's errno.
- Exception
Represents errors that occur during application execution.
- Experimental
This annotation marks methods, classes, constants, and macros as experimental.
- Fiber
A
Fiberis a light-weight execution unit managed by the Crystal runtime. - File
- FileUtils
NOTE To use
FileUtils, you must explicitly import it withrequire "file_utils" - Flags
An enum can be marked with
@[Flags]. - Float
Float is the base type of all floating point numbers.
- Float32
- Float64
- GC
- HTML
Provides HTML escaping and unescaping methods.
- HTTP
The HTTP module contains
HTTP::Client,HTTP::ServerandHTTP::WebSocketimplementations. - Hash(K, V)
A
Hashrepresents a collection of key-value mappings, similar to a dictionary. - INI
NOTE To use
INI, you must explicitly import it withrequire "ini" - IO
The
IOclass is the basis for all input and output in Crystal. - IPSocket
NOTE To use
IPSocket, you must explicitly import it withrequire "socket/ip_socket" - IndexError
Raised when the given index is invalid.
- Indexable(T)
A container that allows accessing elements via a numeric index.
- Int
Int is the base type of all integer types.
- Int128
- Int16
- Int32
- Int64
- Int8
- Intrinsics
- InvalidBigDecimalException
- InvalidByteSequenceError
- Iterable(T)
- Iterator(T)
An
Iteratorallows processing sequences lazily, as opposed toEnumerablewhich processes sequences eagerly and produces anArrayin most of its methods. - JSON
The JSON module allows parsing and generating JSON documents.
- KeyError
Raised when the specified key is not found.
- LLVM
- Levenshtein
Levenshtein distance methods.
- Link
- Log
The
Logclass provides a logging utility that you can use to output messages. - MIME
This module implements a global MIME registry.
- Math
- Mutex
A fiber-safe mutex.
- NamedTuple(**T)
A named tuple is a fixed-size, immutable, stack-allocated mapping of a fixed set of keys to values.
- Nil
The
Niltype has only one possible value:nil. - NilAssertionError
Raised when a
not_nil!assertion fails. - NoReturn
Some expressions won't return to the current scope and therefore have no return type.
- NotImplementedError
Raised when a method is not implemented.
- Number
The top-level number type.
- OAuth
The OAuth module provides an
OAuth::Consumeras specified by RFC 5849. - OAuth2
The OAuth module provides an
OAuth2::Clientas specified by RFC 6749. - Object
Objectis the base type of all Crystal objects. - OpenSSL
The OpenSSL module allows for access to Secure Sockets Layer (SSL) and Transport Layer Security (TLS) encryption, as well as classes for encrypting data, decrypting data, and computing hashes.
- OptionParser
OptionParseris a class for command-line options processing. - OverflowError
Raised when the result of an arithmetic operation is outside of the range that can be represented within the given operands types.
- Path
A
Pathrepresents a filesystem path and allows path-handling operations such as querying its components as well as semantic manipulations. - Pointer(T)
A typed pointer to some memory.
- PrettyPrint
This class implements a pretty printing algorithm.
- Proc(*T, R)
A
Procrepresents a function pointer with an optional context (the closure data). - Process
- Random
Randomprovides an interface for random values generation, using a pseudo random number generator (PRNG). - Range(B, E)
A
Rangerepresents an interval: a set of values with a beginning and an end. - Reference
Referenceis the base class of classes you define in your program. - ReferenceStorage(T)
ReferenceStorage(T)provides the minimum storage for the instance data of an object of typeT.EXPERIMENTAL This type's API is still under development. Join the discussion about custom reference allocation at #13481.
- Regex
A
Regexrepresents a regular expression, a pattern that describes the contents of strings. - RuntimeError
Raised when there is an internal runtime error
- SemanticVersion
Conforms to Semantic Versioning 2.0.0
- Set(T)
Setimplements a collection of values with no duplicates. - Signal
Safely handle inter-process signals on POSIX systems.
- Slice(T)
- Socket
- Spec
Crystal's built-in testing library.
- StaticArray(T, N)
A fixed-size, stack allocated array.
- Steppable
Implements a
#stepmethod for iterating from a value. - String
A
Stringrepresents an immutable sequence of UTF-8 characters. - StringPool
A string pool is a collection of strings.
- StringScanner
StringScannerprovides for lexical scanning operations on aString. - Struct
Structis the base type of structs you create in your program. - Symbol
A symbol is a constant that is identified by a name without you having to give it a numeric value.
- Sync
Synchronization primitives to build concurrent-safe and parallel-safe data structures, so we can embrace concurrency and parallelism with more serenity.
- Syscall
EXPERIMENTAL
- System
- SystemError
- TCPServer
A Transmission Control Protocol (TCP/IP) server.
- TCPSocket
A Transmission Control Protocol (TCP/IP) socket.
- TargetFeature
The annotation allows to assume special CPU model/features for a method.
- Termios
DEPRECATED
- Time
Timerepresents a date-time instant in incremental time observed in a specific time zone. - Tuple(*T)
A tuple is a fixed-size, immutable, stack-allocated sequence of values of possibly different types.
- TypeCastError
Raised when the type cast failed.
- UDPSocket
A User Datagram Protocol (UDP) socket.
- UInt128
- UInt16
- UInt32
- UInt64
- UInt8
- UNIXServer
A local interprocess communication server socket.
- UNIXSocket
A local interprocess communication clientsocket.
- URI
This class represents a URI reference as defined by RFC 3986: Uniform Resource Identifier (URI): Generic Syntax.
- UUID
Represents a UUID (Universally Unique IDentifier).
- Unicode
Provides the
Unicode::CaseOptionsenum for special case conversions like Turkic. - Union(*T)
A union type represents the possibility of a variable or an expression having more than one possible type at compile time.
- VaList
- Value
- Void
Similar in usage to
Nil. - WaitGroup
Suspend execution until a collection of fibers are finished.
- WasiError
- WeakRef(T)
Weak Reference class that allows a referenced object to be garbage-collected.
- WinError
WinErrorrepresents Windows' System Error Codes. - XML
The XML module allows parsing and generating XML documents.
- YAML
The YAML module provides serialization and deserialization of YAML version 1.1 to/from native Crystal data structures, with the additional independent types specified in http://yaml.org/type/