joblib
Python library for lightweight pipelining, including memory caching of results and easy parallel loops.
Official Documentation ↗v1. Check the official docs for the latest API surface.Installation
pip install joblibMethods
No methods match this filter.
Overview
joblib is a Python library for lightweight pipelining, offering memory-efficient persistence and easy parallel loops. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
Parallel and delayed— Runs independent function calls across processes for simple parallelism.joblib.dump— Persists a Python object to disk efficiently, including large NumPy arrays.joblib.load— Loads a previously dumped object, optionally memory-mapping large arrays.
Example
from joblib import Parallel, delayed
results = Parallel(n_jobs=4)(delayed(pow)(x, 2) for x in range(5))
print(results)
Notes
It uses processes by default and threads on request; choose based on whether work is CPU or IO bound. Loading untrusted dumps is unsafe.
Verification
Run a Parallel loop over several inputs and confirm the results come back in the original order.
Errors
The official API reference declares the following error types:
TimeOutError(Parallel(timeout=…) 单任务超时抛出的异常) — official text: “Timeout limit for each task to complete. If any task takes longer a TimeOutError will be raised. Only applied when n_jobs != 1” (source: https://joblib.readthedocs.io/en/latest/generated/joblib.Parallel.html, fetched 2026-11-08T18:29:00+08:00)RuntimeError(同一 Parallel 对象被重复调用时触发的运行时错误) — official text: “Note that the intended usage is to run one call at a time. Multiple calls to the same Parallel object will result in aRuntimeError” (source: https://joblib.readthedocs.io/en/latest/generated/joblib.Parallel.html, fetched 2026-11-08T18:29:00+08:00)
Security
Official security statements captured from the package documentation:
- joblib.load 基于 pickle,可执行任意 Python 代码,禁止加载不可信来源的文件 — “WARNING: joblib.load relies on the pickle module and can therefore execute arbitrary Python code. It should therefore never be used to load files from untrusted sources.” (source: https://joblib.readthedocs.io/en/latest/generated/joblib.load.html, fetched 2026-11-08T18:29:00+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T18:29:00+08:00 via WebFetch https://joblib.readthedocs.io/en/latest/generated/joblib.Parallel.html;WebFetch https://joblib.readthedocs.io/en/latest/generated/joblib.dump.html;WebFetch https://joblib.readthedocs.io/en/latest/generated/joblib.load.html.
Parallel and delayed→ signature from https://joblib.readthedocs.io/en/latest/generated/joblib.Parallel.html; official text: “class joblib.Parallel(n_jobs=default(None), backend=default(None), return_as=‘list’, verbose=default(0), timeout=None, pre_dispatch=‘2 *n_jobs’, batch_size=‘auto’, temp_folder=default(None), *max_nbytes=”joblib.load→ signature from https://joblib.readthedocs.io/en/latest/generated/joblib.load.html; official text: “joblib.load(filename, mmap_mode=None, ensure_native_byte_order=‘auto’)”
FAQ
- Why is joblib faster than pickle for arrays?
- joblib stores NumPy arrays without object overhead and can memory-map them, so reads avoid loading everything into RAM.
- Is joblib.dump safe against untrusted files?
- No. Like pickle it can execute code on load, so only load files you produced or fully trust.
- How do I use threads instead of processes?
- Pass prefer="threads" to Parallel for IO-bound work where process startup would dominate.
Report a problem with this API docOpens a pre-filled issue on GitHub.