Skip to main content
https://img.shields.io/pypi/v/optioneer.svg https://img.shields.io/pypi/status/optioneer.svg https://travis-ci.com/topper-123/optioneer.svg?branch=master https://img.shields.io/badge/License-BSD%203--Clause-blue.svg https://img.shields.io/pypi/pyversions/optioneer.svg

Optioneer makes in-program options, that:

  • are nestable and groupable,

  • are tab-able in the REPL for easy options discoverability

  • give each option a optional doc string, for easily explaining the option

  • may deprecate according to a transparent deprecation cycle

  • may be validated upon change

  • can do custom callbacks

Optioneer is based on the core/config.py module in pandas.

Installation

Installing is easy using pip:

pip install optioneer

Usage guide

In a config.py file set up your options:

from optioneer import Optioneer
options_maker = Optioneer()
options_maker.register_option('api_key', 'abcdefg')
options_maker.register_option('display.width', 200, doc='Width of our display')
options_maker.register_option('display.height', 200, doc='Height of our display')
options_maker.register_option('color', 'red', validator=options_maker.is_str)

options = options_maker.options

Then, in the relevant location of your library, just do from config import options and you’re got your options set up.

Users of your library can now access the options from the relevant location in your package, e.g. if you’ve made it available in the top-level __init__.py of a package called mylib:

>>> import mylib
>>> import mylib.options
Options(
  api_key: No description available.
      [default: abcdefg] [currently: abcdefg]
  color: No description available.
      [default: red] [currently: red]
  display.height: Height of our display
      [default: 200] [currently: 200]
  display.width: Width of our display
      [default: 200] [currently: 200]
  )

Notice how the repr output shows the relevant options and their descriptions.

The relevant options are discoverable using tabs in the REPL:

>>> mylib.options.<TAB>
option.api_key options.color options.display
>>> mylib.options.display.<TAB>
options.display.height options.display.width

You can also easily see the options and their values and docs for subgroups in the repr string:

>>> mylib.options.display
Options(
  display.height: Height of our display
      [default: 200] [currently: 200]
  display.width: Width of our display
      [default: 200] [currently: 200]
  )

Callbacks

By providing a callback when registering options, changing options may trigger a desired actions. For example, if you in your config.py do:

options_maker.register_option('shout', True, callback=lambda x: print("YEAH!"))

Then the user, when changing that option will see:

>>> mylib.options.shout = False
YEAH!

Of course, the callback can be more realistic than above, e.g. logging or setting some internal option or something else.

Deprecating options

If you want to deprecate an option, optioneer allows you to do that:

options_maker.deprecate_option('api_key', msg='An api key is no longer needed')

Now your users get a deprecation warning, if they access this option:

>>> mylib.options.api_key
An api key is no longer needed
C:\Users\TP\Documents\Python\optioneer\optioneer\lib.py:677: FutureWarning: An api key is no longer needed
  warnings.warn(deprecated_option.msg, FutureWarning)
Out[20]: 'abcdefg'

If an options should be renamed and/or a marker should be for when the option will be removed, that is also possible:

options_maker.register_option('display.length', 300, doc='Length of our display')
options_maker.deprecate_option('display.height', redirect_key='display.length',
                               removal_version='v1.3')

Then accessing the option will show

>>> mylib.options.display.height
C:\Users\TP\Documents\Python\optioneer\optioneer\lib.py:689: FutureWarning: 'display.height' is deprecated and will be removed in v1.3, please use 'display.length' instead.
  warnings.warn(msg, FutureWarning)
Out[24]: 300

Deprecated options will not show up in repr output or when tab-completing.

Dependencies

Optioneer has no external dependencies.

Optioneer uses pytest for testing.

License

Optioneer is BSD 3-licensed.

Release files for optioneer 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optioneer 1.0.3
File Size Uploaded
optioneer-1.0.3.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for optioneer 1.0.3
File Interpreter ABI Platform
optioneer-1.0.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 25.4 kB

Release files / optioneer-1.0.3.tar.gz

Download URL optioneer-1.0.3.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
907b22822a2825b18b53dfffdfa50cbc834ddd3efe7a26d9185cb17f951fbcf1
BLAKE2b-256 checksum
How to use checksums
88d1bb5c86aed73d5819e024ad5c9e04232d1d72f7904929a092f9e78e75aaf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

Release files / optioneer-1.0.3-py2.py3-none-any.whl

Download URL optioneer-1.0.3-py2.py3-none-any.whl
Size 10.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b8cef229aba4da721bf3506a2c54dbb248af5e1174c1176bb74fe2cf8407f461
BLAKE2b-256 checksum
How to use checksums
a143d3536369ddb1ff40932c56949418b42b708b13a8afde49b4409fa8e50407
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page