Glossary · Programming

Library vs Framework

A library is code you call when you need it, while a framework calls your code and dictates the structure of your application.

Updated October 6, 2026

A library is a collection of reusable code that your program calls to perform specific tasks, while a framework is a larger skeleton that defines the application's structure and calls your code at the right moments. The difference is often summarized as inversion of control: you call a library, but a framework calls you.

Why it matters

The choice affects how much freedom you keep and how hard it is to leave later. A library such as a date-formatting package is easy to swap out. A framework gives you routing, conventions and structure out of the box, but your code becomes tied to its rules, upgrade cycle and way of working.

Example

Using a library, you control the flow:

import json
data = json.loads(text)   # you decide when to call it

Using a framework, you fill in handlers and the framework decides when they run:

@app.route("/hello")
def hello():              # the framework calls this on a request
    return "Hi"

Common mistakes

  • Pulling in a full framework for a task a small library would solve.
  • Fighting a framework's conventions instead of following them.
  • Assuming the line is sharp; React is called a library, yet many apps treat it as a framework.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.