Everyday Utilities

joblib

The quiet workhorse that saves machine learning models to disk and reruns big Python jobs in parallel.

Install it: pip install joblib

What does it do?

Joblib does two unglamorous but essential jobs extremely well: it saves complex Python objects, especially trained machine learning models, to disk efficiently and reloads them later, and it spreads a slow calculation across multiple processor cores to finish faster. Instead of retraining a machine learning model from scratch every time a program starts, joblib lets you save the trained result once and load it back in seconds. Its parallel processing tools let a data scientist take a slow loop and run pieces of it simultaneously across a computer’s cores with barely any extra code. It’s used so heavily inside scikit-learn, the most popular general machine learning library in Python, that many people use joblib constantly without ever installing it themselves.

See it in action

This saves a trained machine learning model to a file on disk and then loads it back, the same pattern used to avoid retraining a model every time a program starts.

from joblib import dump, load

model = {"weights": [0.1, 0.2, 0.3]}
dump(model, "model.joblib")

loaded_model = load("model.joblib")
print(loaded_model)

Why would a non-developer care?

Training a machine learning model can take minutes, hours, or days, and nobody wants to redo that work every time a program restarts; joblib’s save-and-reload feature is why a deployed model can respond to a prediction request instantly instead of retraining first. Its parallelization also means data scientists use the multiple cores modern computers already have instead of leaving most of the machine idle.

Real-world examples

scikit-learn, used across countless companies and research projects for machine learning, relies on joblib internally for both parallel processing and the model-saving pattern data scientists use every day. If you’ve seen a tutorial where someone saves a trained model as a pickle or joblib file and loads it later to make predictions, that’s this library at work.

Who uses it

Data scientists and machine learning engineers who need to save trained models or speed up computation-heavy Python code across multiple cores.

How it compares to alternatives

For saving models, it’s a faster, more efficient alternative to Python’s built-in pickle module for large numerical data; for parallelism, it’s simpler than Python’s built-in multiprocessing module for the common data-science case, though tools like Dask or Ray scale further for genuinely massive distributed computing.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries