Skip to content
EngineeringAll explainers

Software library: definition, library vs framework, dependencies

A software library is a packaged collection of reusable code that your application imports and calls. This entry covers library vs framework, static and dynamic linking, package managers, transitive dependencies, lockfiles, and open source license risk.

Published: Updated: Reading time: 6 min
On this page

A software library is a packaged collection of reusable code (functions, data structures and classes) that developers import into an application to handle common tasks without writing them from scratch. Your code calls the library; the library doesn't call your code.

Why use one at all? Date parsing, network protocols and cryptography are hard to get right, and other people have already done the work and fixed the bugs. Importing a library lets your team spend its time on the parts of the product that are actually yours. The trade-off is that you now depend on someone else's code, and that comes with costs covered below.

How a software library works

A library exposes an API: documented functions and data contracts that your code can invoke. Everything else stays private. That encapsulation matters, because outside code can't reach into the library's internal state and break it by accident.

How the code gets into your program depends on the language. In compiled languages like C or Rust, a library can be linked statically or dynamically. Static linking copies the object code your program uses into the final binary. Dynamic linking leaves the code in a shared object or DLL that the operating system loads at load time or later at runtime (through calls like dlopen or LoadLibrary). In Node.js or Python, libraries are modules from a package registry that the runtime imports when your code asks for them.

Types of software library

  • A standard library ships with the language itself, like Python's standard library or Rust's std.
  • Third-party libraries come from outside the language project and get installed through a package manager.
  • Static and dynamic libraries differ in how they're linked, as described above.

The surrounding terms overlap, which is part of why people ask what counts as a library. A module is a single unit of code, often one file. A package is the distributable bundle a registry hosts, and it may contain one library or several. An SDK is a broader kit for a specific platform or service that usually includes libraries plus tools, docs and samples.

Library vs framework: inversion of control

The usual line between a software library and a framework is inversion of control. It's a convention rather than a hard rule, but it explains most cases.

With a library, you control the flow. Your code decides what to create, which function to call and what to do with the result. A date library like date-fns runs only when you call one of its formatting functions.

With a framework, the framework controls the flow. It defines the skeleton, manages lifecycle events and routing, and calls your business logic at extension points it chooses. Frameworks call your code. Your code calls libraries.

LibraryFramework
Who controls the flowYour codeThe framework
Typical exampledate-fns, Lodash, NumPyDjango, Angular, Spring
How you adopt itImport it where you need itBuild the app inside its structure
Cost of swapping it outUsually low, one call site at a timeUsually high, often a rewrite

Package managers and dependency trees

In web development and JavaScript development, libraries come from package registries. The main public ones are npm for JavaScript, PyPI for Python, Maven Central for Java and crates.io for Rust. A package manager downloads them and works out which versions fit together.

Here's the catch. Each library you install has its own dependencies, and those have theirs. The result is a tree of transitive dependencies, and an app with fifty direct dependencies can resolve to hundreds or even thousands of packages.

Lockfiles such as package-lock.json or pnpm-lock.yaml keep that tree under control. They pin the exact resolved version of every package and record integrity hashes for packages pulled from a registry. Combined with the Semantic Versioning 2.0.0 specification, this makes installs repeatable across laptops, CI pipelines and production servers. They're not perfectly deterministic, though: git or local dependencies may carry no hash, and the package manager version and platform-specific packages can still change the result.

Technical debt and open source risks

Third-party libraries speed up delivery. Left unmanaged, they also pile up security, maintenance and legal problems that turn into technical debt.

Supply-chain attacks are the most visible risk. Attackers take over maintainer accounts or publish typosquatted packages with names close to popular ones. Teams defend against this by scanning dependencies against known CVEs in CI and checking provenance against the OWASP Software Component Verification Standard. The reference for SBOM contents is still the 2021 NTIA minimum elements, which CISA is now updating.

Abandoned libraries cause slower damage. When a maintainer stops working on a package you rely on, it can block runtime upgrades and leave vulnerabilities unpatched. Before you adopt a library, look at commit frequency, release cadence and how many projects use it. A technical due diligence review usually includes this kind of dependency audit.

Licenses matter too. Permissive licenses (MIT, Apache 2.0, BSD) allow commercial use as long as you keep the copyright and license notices, and Apache 2.0 adds an explicit patent grant. Copyleft licenses such as the GPL can require that combined works you distribute be released under the same license, and the AGPL extends that to software users reach over a network. A license scanner tells you what you're shipping. It doesn't replace legal review.

When to write custom code instead of importing a library

Importing isn't always the right call. Every dependency adds attack surface, bundle size and upgrade work.

Write it yourself when the job is small, like a string helper or a bit of arithmetic you can cover in five lines. For hard domains with lots of edge cases (cryptography, payment compliance, time zones), a well-audited library is the safer choice almost every time. The build-or-import call is best made per dependency, not by habit. If you're weighing it across a whole codebase, that's part of what our custom software development team does.

Frequently asked questions

  • A software library is a packaged collection of pre-written code that you import into your application so you don't have to write common logic yourself. Think date formatting, HTTP requests or encryption. Your code decides when to call it, and the library does one job and hands the result back.

  • The usual distinction is inversion of control. With a library, your code runs the show and calls library functions when it needs them. With a framework, the framework owns the lifecycle and calls your code through hooks, callbacks or conventions. It's a rule of thumb, not a strict naming law, so some tools sit in between.

  • React describes itself as a library for web and native user interfaces. You call it to render components, and it doesn't dictate routing, data fetching or project structure on its own. Meta-frameworks built on top of it, such as Next.js, add those pieces and take over more of the application flow, which is why people argue about the label.

  • Lodash and date-fns in JavaScript, Pandas and NumPy in Python, and Libsodium for cryptography are all widely used libraries. Each one solves a narrow problem well. Your application imports it, calls the functions it needs and ignores the rest.

  • Most teams use a package manager such as npm, pnpm, cargo or pip, commit the lockfile, and follow semantic versioning when they upgrade. Automated scanners like Snyk or Dependabot flag known vulnerabilities in CI. A license scanner and a software bill of materials help you see what you actually ship and under which terms.

Still unanswered
Ask us directly

A senior engineer replies under 4 hours.