package

crystal

1.21.0 / published Aug 13, 2026 / repository

The Crystal standard library

Crystal

Linux CI Build Status macOS CI Build Status AArch64 CI Build Status Windows CI Build Status CircleCI Build Status Join the chat at https://gitter.im/crystal-lang/crystal Code Triagers Badge


Crystal - Born and raised at Manas

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

play.crystal-lang.org

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:

  1. Fork it (https://github.com/crystal-lang/crystal/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

API

  • ArgumentError

    Raised when the arguments are wrong and there isn't a more specific Exception class.

  • Array(T)

    An Array is an ordered, integer-indexed collection of objects of type T.

  • Atomic(T)

    A value that may be updated atomically.

  • Base64

    The Base64 module 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 BigDecimal can represent arbitrarily large precision decimals.

  • BigFloat

    A BigFloat can represent arbitrarily large floats.

  • BigInt

    A BigInt can represent arbitrarily large integers.

  • BigRational

    Rational numbers are represented as the quotient of arbitrarily large numerators and denominators.

  • BitArray

    BitArray is an array data structure that compactly stores bits.

  • Bool

    Bool has only two possible values: true and false.

  • Box(T)

    A Box allows turning any object to a Void* and back.

  • Bytes

    A convenient alias for the most common slice type, a slice of bytes, used for example in IO#read and IO#write.

  • CSV

    Provides methods and classes for parsing and generating CSV (comma-separated values) strings.

  • Channel(T)

    A Channel enables concurrent communication between fibers.

  • Char

    A Char represents a Unicode code point.

  • Class
  • Colorize

    With Colorize you can change the fore- and background colors and text decorations when rendering text on terminals supporting ANSI escape codes.

  • Comparable(T)

    The Comparable mixin 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

    Digest is the base type of hashing algorithms like Digest::MD5, Digest::SHA1, Digest::SHA256, or Digest::SHA512.

  • Dir

    Objects of class Dir are 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

    ENV is a hash-like accessor for environment variables.

  • Enum

    Enum is the base type of all enums.

  • Enumerable(T)

    The Enumerable mixin 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 Fiber is a light-weight execution unit managed by the Crystal runtime.

  • File

    A File instance represents a file entry in the local file system and allows using it as an IO.

  • FileUtils

    NOTE To use FileUtils, you must explicitly import it with require "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::Server and HTTP::WebSocket implementations.

  • Hash(K, V)

    A Hash represents a collection of key-value mappings, similar to a dictionary.

  • INI

    NOTE To use INI, you must explicitly import it with require "ini"

  • IO

    The IO class is the basis for all input and output in Crystal.

  • IPSocket

    NOTE To use IPSocket, you must explicitly import it with require "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)

    The Iterable mixin provides convenience methods to collection classes that provide an #each method that returns an Iterator over the collection.

  • Iterator(T)

    An Iterator allows processing sequences lazily, as opposed to Enumerable which processes sequences eagerly and produces an Array in 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

    A lib can be marked with @[Link(lib : String, *, ldflags : String, static : Bool, framework : String, pkg_config : String, wasm_import_module : String, dll : String)] to declare the library that should be linked when compiling the program.

  • Log

    The Log class 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 Nil type 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::Consumer as specified by RFC 5849.

  • OAuth2

    The OAuth module provides an OAuth2::Client as specified by RFC 6749.

  • Object

    Object is 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

    OptionParser is 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 Path represents 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 Proc represents a function pointer with an optional context (the closure data).

  • Process
  • Random

    Random provides an interface for random values generation, using a pseudo random number generator (PRNG).

  • Range(B, E)

    A Range represents an interval: a set of values with a beginning and an end.

  • Reference

    Reference is 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 type T.

    EXPERIMENTAL This type's API is still under development. Join the discussion about custom reference allocation at #13481.

  • Regex

    A Regex represents 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)

    Set implements a collection of values with no duplicates.

  • Signal

    Safely handle inter-process signals on POSIX systems.

  • Slice(T)

    A Slice is a Pointer with an associated size.

  • Socket
  • Spec

    Crystal's built-in testing library.

  • StaticArray(T, N)

    A fixed-size, stack allocated array.

  • Steppable

    Implements a #step method for iterating from a value.

  • String

    A String represents an immutable sequence of UTF-8 characters.

  • StringPool

    A string pool is a collection of strings.

  • StringScanner

    StringScanner provides for lexical scanning operations on a String.

  • Struct

    Struct is 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

    This module can be included in any Exception subclass that is used to wrap some system error (Errno or WinError).

  • 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

    Time represents 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::CaseOptions enum 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

    Value is the base type of the primitive types (Nil, Bool, Char, Number), Symbol, Pointer, Tuple, StaticArray and all structs.

  • 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

    WinError represents 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/