Professor Turing

Study guides

Framework and library: who calls whom

Last updated: 2026-11-26

A library is a collection of code your program calls when it needs something; a framework controls the overall flow and calls your code instead. The difference is not size or quality. It is the direction of the calls, and two tiny programs with the same app logic show it flipping in a pair of call logs.

Start learning No account needed

1. The direction of the calls

Wikipedia's article on computing libraries describes a library as a set of resources, such as ready-made functions and classes, that programmers draw on while building a program, and says libraries support modular reuse. The article on software frameworks describes software supplying general functionality that a developer specializes by adding code. It also draws the contrast directly: with a library, your code controls the flow and calls library functions when it needs them, while a framework runs the flow and invokes your code at set points. The same article cites the Hollywood Principle: "Don't call us, we'll call you."

The inversion-of-control article names the design principle behind that arrangement. Parts you write are handed control by something outside them, such as a framework, which reverses the procedural habit of your code calling a library to get a generic job done. Both arrangements reuse existing code. What differs is who controls the flow, and a call log makes that visible.

2. A worked example: two tiny programs, one flip

Both programs below compute the same discounted total with the same library function. Program 1 calls that function from its own main function. Program 2 registers two handlers with a small framework and starts its run loop; the framework decides when each handler runs, and one handler calls the library function. For each logged call, the script reads the caller's name from Python while the program runs:

Output from the script scripts/framework-vs-library-worked-example.py:

Two tiny programs, one discount calculation, two control flows.
Question: whose code calls whose?

Program 1, library style. The application calls the library:
  app_main starts
  discount called by app_main
  app_main got 9.0

Program 2, framework style. The app registers handlers and
the framework's run loop decides when each one executes:
  run starts with 2 handlers
  on_start called by run
  on_order called by run
  discount called by on_order
  on_order got 9.0

In program 1 app code calls discount when it chooses to. In
program 2 run calls the app's handlers, and a handler still
calls discount. The framework controls when app code runs.
checks passed

In program 1 the log shows discount called by app_main: your code makes the call. In program 2 on_start and on_order are called by run, the framework's loop, because the app handed those functions over. Inside on_order your code still calls discount, so a framework program can use libraries too. The result, 9.0, is the same. What moved is who decides when your code runs.

3. A common misconception: framework means big and library means small

Size is a poor test. A small framework can be shorter than a large library, and a framework can ship ordinary functions that you call yourself. A better test is control of the flow: find what drives the program and ask who decides when your code runs. A math module you import and call is a library whatever its size. The inversion-of-control article counts callbacks among the patterns that invert control, so a library that calls a function you passed in does a small version of this. A framework does it for the overall flow of your program.

The difference shows up in code you did not write. In a library-style project you can often start reading at your own main function and follow its calls. In a framework-style project the entry points are your handlers, and the framework's documentation is where you learn when they run.

4. Test yourself

Close the page and classify three pieces of a real project in writing. First: a testing package where you write methods and its runner discovers and calls them. Second: a statistics module you import for one average. Third: a web toolkit where you write route handlers and start its server. For each, name the caller of your code. Reopen and compare: framework, library, framework. The one you hesitated on is the step to study again.

For building the habit of writing your own calls before reading framework magic, see how to learn programming without copying code. For exams and interviews that ask about these terms, see how to study for a computer science exam and how to prepare for a coding interview.

What the sources found, and their limits

Wikipedia, "Library (computing)". It defines the library as a collection of development resources and credits libraries with modular reuse. Source: Library (computing), read on 2026-11-26.

Wikipedia, "Software framework". It describes generic functionality that added code specializes, contrasts who controls the flow with a library and with a framework, and cites the Hollywood Principle. Source: Software framework, read on 2026-11-26.

Wikipedia, "Inversion of control". It defines the design principle and contrasts it with procedural code calling libraries. Source: Inversion of control, read on 2026-11-26.

Limits: three encyclopedia articles, not course texts, and the two programs are ours, written small enough to read whole. The script records every call with its caller. All three articles carry a CC BY-SA license.

How Professor Turing helps

Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.

Bring the codebase questions you are working through, such as deciding which parts of a project are yours to start and which run on their own. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, such as a package name, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of handing over the answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through. You must be 18 or older, and guest conversations are deleted 7 days after the last activity.

FAQ

Can one package be a library and a framework? The roles can sit in one package, and the words still name the direction of control. A web framework can include functions you call directly, but once you register handlers and start its run loop, the framework side calls your code, which is program 2's arrangement in the worked example.

Why do frameworks invert control? The inversion-of-control article says it makes the framework extensible: the framework runs the general flow, and the methods you write plug your own behavior into it.

Start with what you're working on

Tell the tutor which codebase question you are stuck on and let it ask you the questions.

Start learning No account needed

See also: what is an API · all study guides