Module leapyear.ext

Quick client

leapyear.ext.user.client(config_file=PosixPath('~/.leapyear_client.ini'), debug=False, **kwargs)

Use environment variables or a configuration file to quickly connect to LeapYear.

This function uses values found in environment variables, a config file, keyword arguments and built-in defaults to try to establish a connection to a LeapYear server. In order of precedence, values are taken from the kwargs of this function, then environment variable, the config file, and finally, default values, if they exist.

By default, the config file is ~/.leapyear_client.ini. The config file requires a [leapyear.io] section where values can be found.

The following table contains the names of the values when specified by particular methods, and the default values if no other value can be determined.

environment variable

ini key/keyword argument

default value

LY_URL

url

'http://localhost:4401'

LY_USERNAME

username

None

LY_PASSWORD

password

None

LY_DEFAULT_ANALYSIS_CACHING

default_analysis_caching

True

LY_DEFAULT_ALLOW_MAX_BUDGET_ALLOCATION

default_allow_max_budget_allocation

True

LY_LOGGING_LEVEL

logging_level

'NOTSET'

At least username and password must be supplied to establish a connection to the LeapYear server.

logging_level should be the name of a logging level in logging.

Example

Contents of ~/.leapyear_client.ini are

[leapyear.io]
username = alice
password = lihjAgsd324$
url = http://api.leapyear.domain.com:4401

Next, we execute a basic test with debug=True to see the values that are passed to the Client constructor.

>>> from leapyear.ext.user import client
>>> import logging
>>> logging.basicConfig()
>>> c = client(debug=True)
DEBUG:leapyear.ext.user:Found config file with [leapyear.io] section.
DEBUG:leapyear.ext.user:Resolved the following values:
DEBUG:leapyear.ext.user:  url <- <str: 'http://api.leapyear.domain.com:4401'>
DEBUG:leapyear.ext.user:  username <- <str: 'alice'>
DEBUG:leapyear.ext.user:  password <- <str: 'lihjAgsd324$'>
DEBUG:leapyear.ext.user:  default_analysis_caching <- <bool: True>
DEBUG:leapyear.ext.user:  default_allow_max_budget_allocation <- <bool: True>
DEBUG:leapyear.ext.user:  logging_level <- <int: 0>
>>> print(c.connected)
True
>>> c.close()
Parameters
  • config_file (pathlib.Path) – Specify an alternate config file.

  • debug (bool) – Set to True to enable extra debugging information. basicConfig() may be useful to run so that debugging information will print to stdout.

Return type

Client