Standard library reference
The Salam libraries
Salam ships with a large standard library, from text and numbers through files, networking, databases and machine learning. Every package has a page here, and every function, struct and constant comes with a plain explanation and a complete example. Every example is run before the site is published, so the output you see is the output you will get.
Basics
coreThe smallest package in Salam, for when the program must not carry on.ioReading from the keyboard, reading and writing files, and writing to standard error.fmtTurning numbers and booleans into text, aligning text, and building a string from a template.convConverting numbers and booleans to text and back, including Persian digits.textConverting a string to UTF-16 and back, for Windows and libraries that want that format.resultReturning either a value or an error from a function, instead of throwing an exception.optionA value that may or may not be there, without nulls and without magic numbers such as minus one.
Text
strEverything to do with text: searching, slicing, replacing, digits, case, and building long strings.unicodeWhat Unicode knows about a character: category, script, writing direction, case, decomposition and composition.arabicNormalising Arabic-script text: Arabic yeh and kaf, vowel marks, tatweel, the zero width non-joiner and digits, for search and comparison.bidiThe Unicode bidirectional algorithm: the right display order when right to left and left to right text are mixed.regexSearching and replacing with a pattern: finding a number, an email address or a date in text and pulling it apart.templateFilling text and HTML templates with values, with automatic escaping for safety.i18nA multilingual program: translating messages, placing values into them and choosing singular or plural.
Numbers and collections
mathThe basic mathematics: powers and roots, logarithms, trigonometry, rounding, minimum and maximum, and the greatest common divisor.randRandom numbers, text and choices: dice, one-time codes, unique identifiers and shuffling a list.statsDescriptive statistics over a list of numbers: mean, median, variance, standard deviation and percentiles.typesRecognising the type of a value from its text: a whole number, a decimal, a boolean or ordinary text?bigintWhole numbers of unlimited size: large factorials, cryptography, and any arithmetic that will not fit in 64 bits.decimalExact decimal numbers for money and accounting, with none of the rounding error of floating point.sortSorting vectors with the default or your own comparison, binary search, and a dozen sorting algorithms to learn from.collectionsData structures: vector and map, stack, queue, deque, set, linked list, priority queue and counter.
System and tools
osFiles, directories, system commands, program arguments and environment variables.os/errorThe last error from a file or process operation: its code, its message and the path that failed.os/platformIdentifying the system the program is running on: the operating system, the processor, the core count and the memory.os/processRunning other programs, capturing their output, waiting for them and stopping them.os/shellRunning a command and getting its exit code, its output and its errors together.os/tempMaking a temporary file or directory under a unique name.os/userWho is running the program, and the standard directories that belong to them.fsFile times and permissions; the base of the file, dir and path packages.fs/dirCreating, listing, copying, moving and removing directories.fs/fileReading and writing files, file information, copying and moving, and MD5 and SHA digests.fs/pathWorking with file paths: joining them, separating the name and the extension, absolute and relative paths, and a safety check.filepathPath functions that never touch the file system; the same work as the fs/path package.envEnvironment variables: reading them with the right type, .env files, the run profile, and masking sensitive values.flagReading command line options such as--port 8080and-vwith the right type, and generating the help text.cliCommand line programs with several commands, likegit commit, and asking the user questions.configReading and writing INI, env and YAML settings files with dotted keys.logRecording what a program does, with levels, a prefix, structured fields, JSON output and writing to a file.debugTools for finding a bug: assertions, a hand-kept call stack, tracing and timing.runtimeFacts about the running program: the system, the memory, the uptime and the build options.testingWriting tests for your code: equality assertions, a pass and fail count, and a summary at the end.errorStructured errors with a kind, a message, a chain of causes, metadata and a retry policy.memWorking with memory directly: allocating and freeing, copying, arenas and pools, and leak checking.termText colour and style, cursor movement, progress bars, reading keys and the mouse, and the terminal size.
Time and concurrency
timeThe current time, durations, formatting and parsing dates, the monotonic clock, timers and tickers.calendarThe Jalali, Hijri and Gregorian calendars: conversion, day arithmetic, month names and time zones.threadHolding and waiting for the threads thatspawncreates.syncMutexes, condition variables, wait groups, read-write locks, semaphores and once, for coordinating threads.atomicA counter and a flag that several threads can change safely without taking a lock by hand.chanA channel for passing values from one thread to another, with a buffer, timeouts and closing.poolRunning one loop in parallel across several processor cores.ctxA context for cancellation and deadlines, passed from the main piece of work down to the smaller ones.
Encoding and data
encodingTurning text and data into Base64, hexadecimal and URL encoding.encoding/jsonBuilding and reading JSON: from a plain string through automatic struct conversion to streaming.encoding/yamlReading YAML by path, building and writing it, and converting it to JSON.encoding/csvReading and writing CSV files, with correct quoting and conversion to a dynamic value.encoding/tomlReading and writing TOML configuration files.encoding/urlTaking a web address apart, building and editing its parameters, and resolving relative addresses.encoding/queryReading and building the query string of a web address, such asq=hello&page=2.encoding/envfileReading and writing.envfiles, with variable substitution.encoding/valueA dynamic value for data whose shape you do not know in advance; the shared language of every format in this group.encoding/serdeDetecting the format of a piece of text and converting JSON, YAML, TOML, XML and CSV into one another.encoding/encerrThe shared error of the format readers: a kind, a message and a position in the text.encoding/msgpackThe compact binary MessagePack format for dynamic values.encoding/binaryWriting and reading numbers as bytes, big-endian or little-endian.encoding/xmlReading, building and writing XML, with XPath, DTD validation, namespaces and a light simple interface.encoding/protobufReading.protofiles, the Protocol Buffers wire encoding, and generating Salam code from them.compressByte buffers, compression methods from RLE through DEFLATE, gzip and checksums.archiveMaking and opening zip and tar archives, reading RAR, and gzipping a file.npyReading and writing NumPy.npyand.npzfiles.excelReading and writing Excel spreadsheets (xlsx and xls), OpenDocument (ods) and CSV.dataReading data for machine learning: CSV tables, batching samples, MNIST and images, and synthetic data.
Network
net/tcpTCP servers and clients: listening, connecting, reading and writing, TLS and a connection pool.net/udpSending and receiving UDP packets, with broadcast and multicast.net/dnsFinding the address of a name and asking for any kind of DNS record.net/mimeThe media type of a file, the Content-Type header, and multipart form bodies.net/proxyConnecting through an HTTP or SOCKS5 proxy, alone or in a chain.net/routerRouting HTTP requests, with parameters, groups and static files.net/httpxSending a raw HTTP request with headers of your own and taking the response as text or bytes.net/emailSending email over SMTP and reading it over IMAP and POP3.net/websocketA two way connection that stays open between browser and server, with rooms for broadcasting.net/httpHTTP servers and clients: handlers, text and JSON responses, cookies and sending requests.net/http/middlewareThe usual security, cache and CORS headers, and request logging, in one call.net/http/validateChecking form input and answering with a 400.net/http/sessionUser sessions over a cookie: keeping data between requests, and a CSRF token.net/http/swaggerWriting OpenAPI documentation for an API and serving the documentation page.net/http2The HTTP/2 protocol from the ground up: frames, HPACK header compression and streams.net/socketioA Socket.IO client: events, acknowledgements, namespaces and automatic reconnection.
Web and browser
domWorking with a web page in the browser: elements, events, timers and JavaScript objects.web/canvasDrawing shapes, text and images on a browser canvas element.web/keysKeyboard state for browser games.webpushSending notifications to browsers from a server, with VAPID keys and the standard encryption.
Security and cryptography
cryptoSHA and MD5 digests, HMAC signatures, secure random numbers and password hashing.jwtMaking and checking JWT tokens, and guarding API routes.tlsSecure TLS 1.3 and 1.2 connections and public key cryptography tools, with no OpenSSL needed.sslA familiar OpenSSL style interface for secure connections, on top of Salam's own TLS.
Network
sshSSH connections, running a command on a server, and working with files over SFTP.ftpAn FTP and FTPS client: listing a directory, uploading and downloading files.rpcJSON-RPC 2.0 and MessagePack-RPC: a server, a client and registering methods.grpcA gRPC server and client over HTTP/2: unary and streaming calls, metadata and status codes.
Database
dbOne interface shared by the database engines, schema migrations and a connection pool.db/sqliteAn SQLite database in one file or in memory.db/mysqlConnecting to MySQL and MariaDB.db/postgresConnecting to PostgreSQL.db/redisA Redis client: keys and values, hashes, lists, sets and publishing.db/elasticsearchAn Elasticsearch and OpenSearch client: documents, search, aggregations, bulk, SQL and index management.db/meilisearchA Meilisearch client: indexes, documents, full text, faceted, hybrid and federated search, settings, tasks and API keys.
Web and services
graphqlA GraphQL server: schemas, resolvers, query execution and HTTP handling.googleGoogle service account authentication for the Google APIs.telegram/botBuilding a bot with the Bot API: messages, buttons, webhooks and a polling loop.nodeA Salam program under Node.js: modules, files, processes and JavaScript objects.awsAmazon S3, SQS and STS, and any S3 compatible service, with Signature Version 4.
Compiler and tools
Machine learning
optimNeural network optimisers: SGD, Adam, RMSProp and learning rate schedules.onnxReading and running ONNX models with no outside dependency.ggufReading GGUF model files, the llama.cpp format.webviewA desktop program with an HTML interface in a native window.tensorMulti dimensional arrays and numeric operations for machine learning.autogradReverse mode automatic differentiation for training models.nnNeural network layers: linear, convolutional, recurrent, transformer, and checkpoints.llmRunning Llama and Qwen language models from a GGUF file.matrixLinear algebra: matrices, systems of equations, decompositions, eigenvalues and statistics.imageReading, editing and saving images, and writing text on them.graphGraph theory: traversal, shortest paths, spanning trees, flow, coloring, communities and centrality.mlClassic machine learning: preprocessing, regression, classification, trees, clustering and evaluation.opencvComputer vision with OpenCV: image processing, features, face detection, neural networks and video.
Every package ships with its own API: salam doc str generates the full reference of one from the source. If the language itself is new to you, start with the course.