Registry / serialization / traitlets

traitlets

JSON →
library5.16.1pypypi✓ verified 27d ago

Traitlets is a Python library that provides a framework for defining attributes with type checking, dynamic default values, and change callbacks. It is currently at version 5.14.3, released on April 19, 2024, and follows a regular release cadence with periodic updates and maintenance improvements.

pip install traitlets
INSTALL
IMPORT
SIG · TRAITLETS
T
traitlets
serializationpythonv5.16.1
Install
1.7s avg
Import
60ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.16.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.064s · 18.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.056s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HasTraits
from traitlets import HasTraits
Correct import path for defining classes with trait attributes.
Unicode
from traitlets import Unicode
Correct import path for defining Unicode trait attributes.
Int
from traitlets import Int
Correct import path for defining Integer trait attributes.
default
from traitlets import default
Correct import path for defining default values for traits.

A simple example demonstrating the use of Traitlets to define a class with a 'username' attribute that defaults to the current system user.

import getpass from traitlets import HasTraits, Unicode, default class Identity(HasTraits): username = Unicode() @default('username') def _default_username(self): return getpass.getuser() identity = Identity() print(identity.username)
Debug
Known issues
breakingTraitlets 5.0 removed support for Python 2 and versions 3.0-3.6, now requiring Python 3.7 or higher.
fix
Upgrade your Python environment to version 3.7 or higher.
affects: 5.0.0
deprecatedThe 'six' library is no longer a dependency as of Traitlets 5.0.0.
fix
Ensure your code does not rely on 'six' for compatibility between Python 2 and 3.
affects: 5.0.0
gotchaUsing 'default' as a method name without the '@default' decorator will not set the default value for the trait.
fix
Decorate the method with '@default('trait_name')' to set the default value.
affects: all
gotchaThe pip tool issued a warning about being run as the 'root' user, which can cause broken permissions and conflicts with the system package manager.
fix
Avoid running pip directly as the 'root' user. It is recommended to use a virtual environment (`python -m venv`) or install packages for the user (`pip install --user`). The `--root-user-action` option can suppress this warning if intended.
affects: all
Errors
Common errors & fixes
TraitError: The 'my_trait' trait of a MyClass instance must be an int, but a value of 'hello' <class 'str'> was specified.
This error occurs when you attempt to assign a value of an incorrect type to a traitlet-defined attribute.
fix
Assign a value that matches the traitlet's specified type (e.g., an `int` for an `Int` trait, a `str` for a `Unicode` trait).
traitlets.config.loader.ConfigError: No such config option: 'MyClass.some_nonexistent_trait'
This error indicates that a configuration file (e.g., for a Jupyter application) attempts to set a traitlet that either does not exist, is misspelled, or is not applicable to the specified class.
fix
Review your configuration file and correct the traitlet option name, ensuring it matches an existing trait on the target class.
TypeError: _default_my_trait() missing 1 required positional argument: 'owner'
This error arises when you define a method to provide a dynamic default value for a traitlet (e.g., `_default_my_trait`) but omit the `owner` argument from its signature.
fix
Add the `owner` argument to the method signature: `def _default_my_trait(self, owner): return some_value`.
Upgrade
Version history
5.16.1latest on PyPI · released Aug 3, 2026
Audit
Dependencies
ipython_genutilsrequiredProvides utility functions for IPython components.
sixrequiredEnsures compatibility between Python 2 and 3.
decoratorrequiredSimplifies the creation of decorators.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
traitlets — pip install traitlets · libregistry