Skip to content

Handle Config

Config dataclass

proxy: typ.Optional[pydantic.AnyUrl] class-attribute

JijZept API Config.

Attributes:

Name Type Description
query_url str

Endpoint for Query API.

post_url str

Endpoint for Post Instance API.

proxy str

Proxy URL. Defaults to None.

token str

Secret token to connect API.

__init__(*, url=None, token=None, proxy=None, config=None, config_env='default')

Parameters:

Name Type Description Default
url str | dict[str, str] | None

Endpoint for connecting to JijZept API. If you want to set

None
token str | None

token to connect JijZept API. Defaults to None.

None
proxy str | None

proxy server. Defaults to None.

None
config PATH_TYPE | None

config file path. Defaults to None.

None
config_env str

config environment name. Defaults to "default".

'default'

Raises:

Type Description
jijzept.exception.ConfigError

parse error.

TypeError

url schema or config path is invaild.

pydantic.error_wrappers.ValidationError

url schema or config path is invaild.

config_file_path(file_path)

Get config file path.

Configuration files are explored in the following order When found, the path to the file is returned, or None if not found. If the user specifies a file path in file_path arguments, it is returned in preference to all of the following.

The search goes for the jijzept and jijzept_config.toml files in the following directories.

  1. Current directory: pathlib.Path().cwd()
  2. $XDG_CONFIG_HOME
  3. ~/.config

The search order of this function is the priority order of config files in JijZept.

Parameters:

Name Type Description Default
file_path typ.Union[pathlib.Path, str, None]

file path. Defaults to None.

required

Returns:

Type Description
typ.Optional[pathlib.Path]

pathlib.Path | None: config file path

load_config(*, file_path, config='default')

Load config file (TOML file).

Parameters:

Name Type Description Default
file_path pathlib.Path

path to config file.

required
config str

loading enviroment name. Defaults to 'default'.

'default'

Raises:

Type Description
TypeError

if 'config' enviroment is not defined in config file.

Returns:

Name Type Description
dict dict

ex. {'token': 'xxxx', 'url': 'xxxx'}


Last update: 2023年3月17日