Traitlets: Python Configuration System

5.14.3 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →