otp.Session#
- class Session(config=None, clean_up=True, copy=True, override_env=False, redirect_logs=True)[source]#
Bases:
object
A class for setting up working OneTick session. It keeps configuration files during the session and allows to manage them. When instance is out of scope, then instance cleans up config files and configuration. There are several ways to leave the scope: .close(), __del__() and __exit__() methods.
It is allowed to have only one alive instance in the process.
If you don’t use Session’s instance, then
ONE_TICK_CONFIG
environment variable should be set to be able to work with OneTick.If config file is not set then temporary is generated. Config includes locator and acl file, and if they are not set, then they are generated
- Parameters
config (str, Config, optional) – Path to an existing OneTick config file; if it is not set, then config will generated. If config is not set, then temporary config is generated. Default is None.
clean_up (bool, optional) – A flag to control cleaning up process: if it is True then all temporary generated files will be automatically removed. It is helpful for debugging. The flag affects only generated files, but does not externally passed. Default is True.
copy (bool, optional) – A flag to control file copy process: if it is True then all externally passed files will be copied before usage, otherwise all modifications during an existing session happen directly with passed config files. NOTE: we suggest to set this flag only when you fully understand it’s effect. Default is True.
override_env (bool, optional) –
If flag is True, then unconditionally os.environ[‘ONE_TICK_CONFIG’] will be overriden with a config that belongs to a Session. Otherwise os.envrion[‘ONE_TICK_CONFIG’] will be defined in the scope of session only when externally ‘ONE_TICK_CONFIG’ is not defined. For example, it is helpful when you test ascii_loader that uses ‘ONE_TICK_CONFIG’ only.
Default is False ( default is False, because overriding external evnironment variable might be not obvious and desirable )
redirect_logs (bool, optional) – If flag is True, then OneTick logs will be redirected into a temporary log file. Otherwise logs will be mixed with output. Default is True.
- Variables
- use_stub(stub_name)[source]#
Adds stub-DB into the session. The shortcut for
.use(otp.DB(stub_name))
- Parameters
stub_name (str) – name of the stub
- property config#
- property acl#
- property locator#
- property license#
- property ts_databases#
- property databases#