Skip to main content

Library

In Turkish
Kütüphane
Pronunciation
LY-brer-ee
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/library

In short

A library is a collection of ready-made code, such as functions and classes, that a program calls to do common jobs without writing that code itself.

What is a library in programming?

Libraries package solutions that many programs need. Instead of writing your own date handling, you call a date library; instead of building charts from scratch, you use a charting library. Every language also ships a standard library with the basics, such as strings, collections, files and networking, and package managers such as npm, pip and Cargo add hundreds of thousands of third-party ones.

Your code stays in charge when it uses a library: it decides when to call format(date) or axios.get(url), and the library does its job and returns. This is the classic difference from a framework, which provides the overall structure and calls your code at the right moments. It is summed up as: you call a library, a framework calls you.

Using a library means taking on a dependency. Its bugs, security issues, license and future maintenance become partly your concern, and each library you add may pull in further libraries of its own. Popular, well-maintained libraries with clear versions are a safer choice, and lockfiles keep the exact versions reproducible.

A common misconception is that React is a framework. React describes itself as a library for building user interfaces: it handles components and rendering, while routing, data loading and building are left to other libraries or to frameworks such as Next.js that are built on top of it.

Key takeaways

  • A library is reusable code your program calls to do common jobs.
  • Each language has a standard library; package managers add third-party ones.
  • You call a library, while a framework calls your code.
  • Every library is a dependency with its own bugs, license and upkeep.
  • React is a UI library; Next.js is a framework built on it.

Example

Using a library instead of writing the code yourself (Python)python
# Standard library: ships with Python
import json
from datetime import date

print(json.dumps({"today": date.today().isoformat()}))

# Third-party library: installed with  pip install requests
import requests

response = requests.get("https://api.github.com/repos/python/cpython")
print(response.json()["stargazers_count"])
# Your code decides when to call the library, then carries on.

Readers ask

What is the difference between a library and a framework?

With a library, your code is in control and calls the library when it needs something. With a framework, the framework is in control: it defines the structure and calls your code. This is known as inversion of control.

What is a standard library?

The library that comes with a programming language, covering common needs such as text, math, files, dates and networking. Python's "batteries included" standard library is known for being especially large.

What is the difference between a library and a package?

A package is the unit a package manager installs, with a name, version and metadata. It usually contains a library, though it can also contain tools or other files.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings