Python supercharged for fastai development
Project description
Welcome to fastcore
[!NOTE]
fastcore v2
In July 2026 we released fastcore v2, which removes or relocates a number of APIs that had accumulated better alternatives. If you use
from fastcore.utils import *(orfastcore.all), most of these changes won’t affect you. The breaking changes:Paramis gone fromfastcore.script; use plain type annotations with docments, ortyping.Annotated[type, "help"], optionally with adictof argparse arguments for advanced features.L’sstarmap,starfilter, and the otherstar*/rstar*methods are replaced by thestarandrstarfunction adapters, which compose with everyLmethod (e.g.t.map(star(f))); relatedly,spreadis replaced bystar, anddspreadis renamed todstar. Async helpers now live in the newfastcore.aiomodule:run_sync,iter_sync, andctx_syncmoved there fromnet, andmaybe_await,then,mapa,acache,reawaitable,is_async_callable, and the other async utilities moved there fromxtras.Configand the config file functions moved fromfoundationtoxtras.fastcore.netlost its request builders (urlrequest,urlsend,do_request,urlcheck) andclean_type_stris gone.parallel_genis removed; the stdlibProcessPoolExecutorinitializerpattern replaces it (fastai’sparallel_tokenizeshows the recipe). Python 3.11 or later is now required. If you need the old APIs, pinfastcore<2.
Python is a powerful, dynamic language. Rather than bake everything into the language, it lets the programmer customize it to make it work for them. fastcore uses this flexibility to add to Python features inspired by other languages we’ve loved, mixins from Ruby, and currying, binding, and more from Haskell. It also adds some “missing features” and cleans up some rough edges in the Python standard library, such as simplifying parallel processing, and bringing ideas from NumPy over to Python’s list type.
Here are some tips on using fastcore:
- Liberal imports: Use
from fastcore.module import *freely. The library is designed for safe wildcard imports. - Enhanced list operations: Substitute
listwithL. This provides advanced indexing, method chaining, and additional functionality while maintaining list-like behavior. - Extend existing classes: Apply the
@patchdecorator to add methods to classes, including built-ins, without subclassing. - Streamline class initialization: In
__init__methods, usestore_attr()to efficiently set multiple attributes, reducing repetitive assignment code. - Explicit keyword arguments: Apply the
delegatesdecorator to functions to replace**kwargswith specific parameters, enhancing IDE support and documentation. - Optimize parallel execution: Use fastcore’s enhanced
ThreadPoolExecutorandProcessPoolExecutorfor simplified concurrent processing. - Expressive testing: Prefer fastcore’s testing functions like
test_eq,test_ne,test_closefor more readable and informative test assertions. - Advanced file operations: Use the extended
Pathclass, which adds methods likels(),read_json(), and others topathlib.Path. - Flexible data structures: Convert between dictionaries and attribute-access objects using
dict2objandobj2dictfor more intuitive data handling. - Functional programming paradigms: Use tools like
compose,maps, andfilter_exto write more functional-style Python code. - Documentation: Use
docmentswhere possible to document parameters of functions and methods. - Time-aware caching: Apply the
timed_cachedecorator to add time-based expiration to the standardlru_cachefunctionality. - Simplified CLI creation: Use
fastcore.scriptto easily transform Python functions into command-line interfaces.
For example, L is a drop-in replacement for list with extra superpowers:
x = L(1,2,3,4)
test_eq(x[[0,3]], [1,4]) # index with a collection
test_eq(x.map(lambda o:o*2), [2,4,6,8])
test_eq(x.filter(lambda o:o>2), [3,4])
x += [5]
test_eq(x.unique(), [1,2,3,4,5])
Tutorials
- Quick tour: A quick tour of a few highlights from fastcore.
- fastcore: an underrated Python library: A tour of some of the features of fastcore.
- API list: A succinct list of all functions and methods in fastcore.
Getting started
To install fastcore run: conda install fastcore -c fastai (if you use Anaconda, which we recommend) or pip install fastcore. For an editable install, clone this repo and run: pip install -e ".[dev]". fastcore is tested to work on Ubuntu, macOS and Windows (versions tested are those shown with the -latest suffix here).
fastcore contains many features, including:
fastcore.test: Simple testing functionsfastcore.foundation: Mixins, delegation, composition, and morefastcore.xtras: Utility functions to help with functional-style programming, parallel processing, and more
To get started, we recommend you read through the fastcore tour.
Contributing
After you clone this repository, please run nbdev_install_hooks in your terminal. This sets up git hooks, which clean up the notebooks to remove the extraneous stuff stored in the notebooks (e.g. which cells you ran) which causes unnecessary merge conflicts.
To run the tests in parallel, launch nbdev_test.
Before submitting a PR, check that the local library and notebooks match.
- If you made a change to the notebooks in one of the exported cells, you can export it to the library with
nbdev_prepare. - If you made a change to the library, you can export it back to the notebooks with
nbdev_update.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastcore-2.1.14.tar.gz.
File metadata
- Download URL: fastcore-2.1.14.tar.gz
- Upload date:
- Size: 128.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0303cbb2db2dd1a34b2c81a62fd4af5f2dcbc32e59cbac233d855da2920f4969
|
|
| MD5 |
ca0d0cc8f161f4bbf2b444b8b5b4dbcf
|
|
| BLAKE2b-256 |
a5e0488f432a8c1f69ac7e23249d46e8c3eac96acd58c17703a4c846dce640f2
|
File details
Details for the file fastcore-2.1.14-py3-none-any.whl.
File metadata
- Download URL: fastcore-2.1.14-py3-none-any.whl
- Upload date:
- Size: 134.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29028015ba07e19627cee2b100a8a3047ea150136a8c67948f90545e43275192
|
|
| MD5 |
93989a14c114e2fae28fe5c24e0839c6
|
|
| BLAKE2b-256 |
f6abca861804c5dc8ef9660041f43ab89a0dad3e8ea2f41b809549cc89d95c86
|