[IPython-dev] Using traitlets.config outside of IPython

MinRK benjaminrk at gmail.com
Wed Jan 25 15:08:31 EST 2017


On Wed, Jan 25, 2017 at 5:24 PM, Thomas Kluyver <takowl at gmail.com> wrote:

> On 25 January 2017 at 16:04, G Jones <glenn.caltech at gmail.com> wrote:
>
>> I am really intrigued by the design and features of the traitlets.config
>> system that IPython uses for configuration. I am considering using it for a
>> project of my own, but I am not sure if it is a good fit. To help decide, I
>> wanted to look to see how other projects are using it, but so far I haven't
>> really found any outside of the IPython/Jupyter ecosystem. This in itself
>> is a bit worrying; maybe it's too specialized to the needs of IPython? Are
>> there any other projects using traitlets.config that people know of?
>
>
> Traitlets is a lightweight clone of Enthought's traits package; you might
> be able to find more projects using that. I think matplotlib was thinking
> of using traitlets, but I don't think they were going to use the config
> part.
>
>
>> Any advice about using it for another project as opposed to more
>> traditional yaml or ConfigParser style configuration?
>
>
> The big downside of traitlets for config is that it exposes your class
> names as the keys for config options, so changing the structure of classes
> in later versions of your code can break people's config unless you write
> compatibility shims for them.
>
> The way we use it in Jupyter is mostly with executable .py config files.
> That's convenient for users editing them by hand, but doesn't really allow
> programmatic modification (e.g. if you want a GUI settings dialog). We use
> JSON files for saving config from the application, but then there's a
> potential source of confusion with different config files setting the same
> things.
>

My favorite part of the Python config files is the ability to put logic in
the config file - e.g. use SSL if a cert is present, listen on the IP
address for eth1, load my notebook password from my keychain, etc. From a
maintainer perspective, the nicest part of traitlets config is probably the
ability to automatically expose a configurable trait with
`.tag(config=True)`. This allows extensions to fairly easily integrate with
the existing config system when you have extensions like we do, and allows
us to do our current "Everything is configurable!", which has complications
as well.

But Thomas is right about downsides, especially exposing your class names
and hierarchy as a public configuration API. Another downside is tying
configuration to instances, making access to config difficult in things
like class and staticmethods.

I'd certainly be happy for more help on traitlets, but honestly I think
it's unlikely to be a good fit for most projects, especially small ones
that aren't full of extension points. A simple yaml/ini config file would
probably be easier to manage.

You could even build a config system where you have a simple yaml file, but
your objects still load their default values from config using traitlets
(i.e. using traitlets for config doesn't mean you have to use
traitlets.config).

-Min


>
>
> Thomas
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20170125/75d9de3b/attachment.html>


More information about the IPython-dev mailing list