flaretool package

Subpackages

Submodules

flaretool.VERSION module

flaretool.basemodels module

class flaretool.basemodels.BaseDataModel

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

flaretool.command module

flaretool.command.cli()
flaretool.command.main()

flaretool.common module

class flaretool.common.requests

Bases: object

static delete(url, **kwargs) Response
static get(url, **kwargs) Response
static head(url, **kwargs) Response
static post(url, **kwargs) Response
static put(url, **kwargs) Response
static request(method: str, url: str, auth_enabled: bool = False, **kwargs) Response

Send an HTTP request with the specified method, URL, and optional parameters.

Parameters:
  • method (str) – The HTTP method to use for the request (e.g., ‘GET’, ‘POST’, ‘PUT’, ‘DELETE’).

  • url (str) – The URL to send the request to.

  • auth_enabled (bool, optional) – Whether to force authentication for the request. Defaults to False.

  • **kwargs – Additional keyword arguments to be passed to the underlying request method.

Returns:

The response object representing the server’s response to the request.

Return type:

Response

Raises:

FlareToolNetworkError – If the request is made to a Flare service and the response status code is 403.

flaretool.constants module

class flaretool.constants.ConsoleColor

Bases: object

BG_BLACK = '\x1b[40m'
BG_BLUE = '\x1b[44m'
BG_CYAN = '\x1b[46m'
BG_DEFAULT = '\x1b[49m'
BG_GREEN = '\x1b[42m'
BG_MAGENTA = '\x1b[45m'
BG_RED = '\x1b[41m'
BG_WHITE = '\x1b[47m'
BG_YELLOW = '\x1b[43m'
BLACK = '\x1b[30m'
BLUE = '\x1b[34m'
BOLD = '\x1b[1m'
COLOR_DEFAULT = '\x1b[39m'
CYAN = '\x1b[36m'
GREEN = '\x1b[32m'
INVISIBLE = '\x1b[08m'
MAGENTA = '\x1b[35m'
RED = '\x1b[31m'
RESET = '\x1b[0m'
REVERCE = '\x1b[07m'
UNDERLINE = '\x1b[4m'
WHITE = '\x1b[37m'
YELLOW = '\x1b[33m'
class flaretool.constants.Country(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

AD = 'Andorra'
AE = 'United Arab Emirates'
AF = 'Afghanistan'
AG = 'Antigua and Barbuda'
AI = 'Anguilla'
AL = 'Albania'
AM = 'Armenia'
AO = 'Angola'
AQ = 'Antarctica'
AR = 'Argentina'
AS = 'American Samoa'
AT = 'Austria'
AU = 'Australia'
AW = 'Aruba'
AX = 'Åland Islands'
AZ = 'Azerbaijan'
BA = 'Bosnia and Herzegovina'
BB = 'Barbados'
BD = 'Bangladesh'
BE = 'Belgium'
BF = 'Burkina Faso'
BG = 'Bulgaria'
BH = 'Bahrain'
BI = 'Burundi'
BJ = 'Benin'
BL = 'Saint Barthélemy'
BM = 'Bermuda'
BN = 'Brunei Darussalam'
BO = 'Bolivia, Plurinational State of'
BQ = 'Bonaire, Sint Eustatius and Saba'
BR = 'Brazil'
BS = 'Bahamas'
BT = 'Bhutan'
BW = 'Botswana'
BY = 'Belarus'
BZ = 'Belize'
CA = 'Canada'
CD = 'Congo, The Democratic Republic of the'
CF = 'Central African Republic'
CG = 'Congo'
CH = 'Switzerland'
CI = "Côte d'Ivoire"
CK = 'Cook Islands'
CL = 'Chile'
CM = 'Cameroon'
CN = 'China'
CO = 'Colombia'
CR = 'Costa Rica'
CU = 'Cuba'
CV = 'Cabo Verde'
CW = 'Curaçao'
CY = 'Cyprus'
CZ = 'Czechia'
DE = 'Germany'
DJ = 'Djibouti'
DK = 'Denmark'
DM = 'Dominica'
DO = 'Dominican Republic'
DZ = 'Algeria'
EC = 'Ecuador'
EE = 'Estonia'
EG = 'Egypt'
ER = 'Eritrea'
ES = 'Spain'
ET = 'Ethiopia'
FI = 'Finland'
FJ = 'Fiji'
FK = 'Falkland Islands (Malvinas)'
FM = 'Micronesia, Federated States of'
FO = 'Faroe Islands'
FR = 'France'
GA = 'Gabon'
GB = 'United Kingdom'
GD = 'Grenada'
GE = 'Georgia'
GF = 'French Guiana'
GG = 'Guernsey'
GH = 'Ghana'
GI = 'Gibraltar'
GL = 'Greenland'
GM = 'Gambia'
GN = 'Guinea'
GP = 'Guadeloupe'
GQ = 'Equatorial Guinea'
GR = 'Greece'
GT = 'Guatemala'
GU = 'Guam'
GW = 'Guinea-Bissau'
GY = 'Guyana'
HK = 'Hong Kong'
HN = 'Honduras'
HR = 'Croatia'
HT = 'Haiti'
HU = 'Hungary'
ID = 'Indonesia'
IE = 'Ireland'
IL = 'Israel'
IM = 'Isle of Man'
IN = 'India'
IO = 'British Indian Ocean Territory'
IQ = 'Iraq'
IR = 'Iran, Islamic Republic of'
IS = 'Iceland'
IT = 'Italy'
JE = 'Jersey'
JM = 'Jamaica'
JO = 'Jordan'
JP = 'Japan'
KE = 'Kenya'
KG = 'Kyrgyzstan'
KH = 'Cambodia'
KI = 'Kiribati'
KM = 'Comoros'
KN = 'Saint Kitts and Nevis'
KP = "Korea, Democratic People's Republic of"
KR = 'Korea, Republic of'
KW = 'Kuwait'
KY = 'Cayman Islands'
KZ = 'Kazakhstan'
LA = "Lao People's Democratic Republic"
LB = 'Lebanon'
LC = 'Saint Lucia'
LI = 'Liechtenstein'
LK = 'Sri Lanka'
LR = 'Liberia'
LS = 'Lesotho'
LT = 'Lithuania'
LU = 'Luxembourg'
LV = 'Latvia'
LY = 'Libya'
MA = 'Morocco'
MC = 'Monaco'
MD = 'Moldova, Republic of'
ME = 'Montenegro'
MF = 'Saint Martin (French part)'
MG = 'Madagascar'
MH = 'Marshall Islands'
MK = 'North Macedonia'
ML = 'Mali'
MM = 'Myanmar'
MN = 'Mongolia'
MO = 'Macao'
MP = 'Northern Mariana Islands'
MQ = 'Martinique'
MR = 'Mauritania'
MS = 'Montserrat'
MT = 'Malta'
MU = 'Mauritius'
MV = 'Maldives'
MW = 'Malawi'
MX = 'Mexico'
MY = 'Malaysia'
MZ = 'Mozambique'
NA = 'Namibia'
NC = 'New Caledonia'
NE = 'Niger'
NF = 'Norfolk Island'
NG = 'Nigeria'
NI = 'Nicaragua'
NL = 'Netherlands'
NO = 'Norway'
NP = 'Nepal'
NR = 'Nauru'
NU = 'Niue'
NZ = 'New Zealand'
OM = 'Oman'
PA = 'Panama'
PE = 'Peru'
PF = 'French Polynesia'
PG = 'Papua New Guinea'
PH = 'Philippines'
PK = 'Pakistan'
PL = 'Poland'
PM = 'Saint Pierre and Miquelon'
PR = 'Puerto Rico'
PS = 'Palestine, State of'
PT = 'Portugal'
PW = 'Palau'
PY = 'Paraguay'
QA = 'Qatar'
RE = 'Réunion'
RO = 'Romania'
RS = 'Serbia'
RU = 'Russian Federation'
RW = 'Rwanda'
SA = 'Saudi Arabia'
SB = 'Solomon Islands'
SC = 'Seychelles'
SD = 'Sudan'
SE = 'Sweden'
SG = 'Singapore'
SI = 'Slovenia'
SK = 'Slovakia'
SL = 'Sierra Leone'
SM = 'San Marino'
SN = 'Senegal'
SO = 'Somalia'
SR = 'Suriname'
SS = 'South Sudan'
ST = 'Sao Tome and Principe'
SV = 'El Salvador'
SX = 'Sint Maarten (Dutch part)'
SY = 'Syrian Arab Republic'
SZ = 'Eswatini'
TC = 'Turks and Caicos Islands'
TD = 'Chad'
TG = 'Togo'
TH = 'Thailand'
TJ = 'Tajikistan'
TK = 'Tokelau'
TL = 'Timor-Leste'
TM = 'Turkmenistan'
TN = 'Tunisia'
TO = 'Tonga'
TR = 'Turkey'
TT = 'Trinidad and Tobago'
TV = 'Tuvalu'
TW = 'Taiwan, Province of China'
TZ = 'Tanzania, United Republic of'
UA = 'Ukraine'
UG = 'Uganda'
US = 'United States'
UY = 'Uruguay'
UZ = 'Uzbekistan'
VA = 'Holy See (Vatican City State)'
VC = 'Saint Vincent and the Grenadines'
VE = 'Venezuela, Bolivarian Republic of'
VG = 'Virgin Islands, British'
VI = 'Virgin Islands, U.S.'
VN = 'Viet Nam'
VU = 'Vanuatu'
WF = 'Wallis and Futuna'
WS = 'Samoa'
YE = 'Yemen'
YT = 'Mayotte'
ZA = 'South Africa'
ZM = 'Zambia'
ZW = 'Zimbabwe'

flaretool.decorators module

flaretool.decorators.network_required(func)

ネットワーク接続のチェックを行い、接続されている場合には指定されたメソッドを実行します。 接続されていない場合にはFlareToolNetworkErrorを発生させます。

Parameters:

func (callable) – ネットワーク接続を確認した後に実行するメソッド。

Returns:

デコレートされた関数。

Return type:

callable

Raises:

FlareToolNetworkError – ネットワークに接続されていない場合に発生する例外。

flaretool.decorators.repeat(tries: int, interval: float = 0)

指定された間隔で関数を指定回数再実行するデコレーター。

Parameters:
  • tries (int) – リピートする回数

  • interval (float, optional) – 実行間隔(秒単位)。デフォルト値は0。

Returns:

デコレートされた関数

Return type:

function

Examples

>>> @repeat(5, 3)
... def print_hello():
...     print("Hello, world!")
...     if some_condition: # 実行を止めたい場合の条件
...         raise StopIteration("Stop the loop")
>>> print_hello()
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
flaretool.decorators.retry(tries: int, delay: float = 0, backoff: float = 1, target_exception: Exception = None)

指定された例外(またはすべての例外)が発生した場合に関数をリトライするデコレーター。

Parameters:
  • tries (int) – 最大リトライ回数。

  • delay (float) – 最初のリトライまでの遅延秒数。デフォルトは0。

  • backoff (float) – リトライ間の遅延時間を増加させる係数。デフォルトは1。

  • target_exception (Exception, optional) – リトライのトリガーとなる例外クラス。 Noneの場合はすべての例外をキャッチします。デフォルトはNone。

Returns:

デコレートされた関数の戻り値。

Return type:

function

Raises:

Exception – 最後のリトライでも例外が発生した場合、その例外を発生させる。

Examples

>>> @retry(3, target_exception=ValueError)
... def my_function():
...    # Some code that may raise a ValueError
...    print("Function executed successfully")
...    raise ValueError("Error")
...    pass
>>> try:
...    my_function()
... except ValueError:
...    print("ValueError occurred")
Function executed successfully
Function executed successfully
Function executed successfully
ValueError occurred
flaretool.decorators.timeout(timeout: int | float)

指定した時間内に処理が完了しない場合に TimeoutError を発生させるデコレーター。

Parameters:

timeout (int or float) – タイムアウト時間(秒)。

Returns:

タイムアウト付きのデコレーター。

Return type:

function

Raises:

TimeoutError – タイムアウトが発生した場合に送出されます。

Examples

>>> @timeout(5)
... def my_function():
...    # Some time-consuming operation
...    time.sleep(10)
...    return "Operation completed"
>>> try:
...    result = my_function()
...    print(result)
... except TimeoutError:
...    print("Operation timed out")
Operation timed out
flaretool.decorators.timer(func)

デコレートされた関数の実行時間を測定するデコレーター。 flaretoolのloggerに出力。

Parameters:

timeout (int or float) – タイムアウト時間(秒)。

Returns:

実行時間を表示し、元の関数の結果を返すラッパー関数。

Return type:

function

Examples

>>> # Logger Setup
... from flaretool.logger import setup_logger
... logger = setup_logger(logging.DEBUG, console=True)
...
>>> @timer
... def example_function(x):
...     time.sleep(x)
...     return x
>>> example_function(2)
[2024-08-01 00:00:00,000] DEBUG : example_function took 2.0000 seconds to execute.
flaretool.decorators.type_check(func)

型チェックを行うデコレーター

Parameters:

func (callable) – 型チェックを行う関数。

Returns:

デコレートされた関数。

Return type:

callable

Raises:

TypeError – 引数の型が予期された型と一致しない場合に発生します。

Examples

>>> @type_check
... def my_function(arg1: int, arg2: str):
...     # 関数の処理...
...     pass
>>> my_function(10, "Hello")
10 Hello
>>> my_function("10", 20)
TypeError: Argument 'arg1' has unexpected type 'str' (expected 'int').

flaretool.enums module

class flaretool.enums.Base64Mode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

DECODE = 2
ENCODE = 1
class flaretool.enums.ConversionMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

FULL_WIDTH = 2
HALF_WIDTH = 1
LOWER = 4
UPPER = 3
class flaretool.enums.HashMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

MD5 = 1
SHA1 = 2
SHA256 = 3
SHA512 = 4

flaretool.errors module

exception flaretool.errors.AuthenticationError(message: str = None)

Bases: FlareToolError

exception flaretool.errors.FlareToolError(message: str = None)

Bases: Exception

Base exception class for FlareTool errors.

exception flaretool.errors.FlareToolNetworkError(message=None, http_body=None, http_status=None, json_body=None, headers=None, code=None, **param)

Bases: FlareToolError

flaretool.logger module

flaretool.logger.get_logger(logger_name: str = 'flaretool') Logger
flaretool.logger.setup_logger(loglevel: int = 20, logger_name: str = 'flaretool', console: bool = True, file: bool = False, file_name: str = 'flaretool.log', rotating: bool = False, max_bytes: int = 1024000, backup_count: int = 5, extra: bool = False, encoding: str = 'utf-8') Logger

flaretool.settings module

class flaretool.settings.BaseSettings(_case_sensitive: bool | None = None, _nested_model_default_partial_update: bool | None = None, _env_prefix: str | None = None, _env_file: DotenvType | None = PosixPath('.'), _env_file_encoding: str | None = None, _env_ignore_empty: bool | None = None, _env_nested_delimiter: str | None = None, _env_parse_none_str: str | None = None, _env_parse_enums: bool | None = None, _cli_prog_name: str | None = None, _cli_parse_args: bool | list[str] | tuple[str, ...] | None = None, _cli_settings_source: CliSettingsSource[Any] | None = None, _cli_parse_none_str: str | None = None, _cli_hide_none_type: bool | None = None, _cli_avoid_json: bool | None = None, _cli_enforce_required: bool | None = None, _cli_use_class_docs_for_groups: bool | None = None, _cli_exit_on_error: bool | None = None, _cli_prefix: str | None = None, _cli_flag_prefix_char: str | None = None, _cli_implicit_flags: bool | None = None, _cli_ignore_unknown_args: bool | None = None, _cli_kebab_case: bool | None = None, _secrets_dir: PathType | None = None, *, api_key: str | None = None)

Bases: BaseSettings

api_key: str | None
model_config: ClassVar[SettingsConfigDict] = {'arbitrary_types_allowed': True, 'case_sensitive': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_exit_on_error': True, 'cli_flag_prefix_char': '-', 'cli_hide_none_type': False, 'cli_ignore_unknown_args': False, 'cli_implicit_flags': False, 'cli_kebab_case': False, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_prefix': '', 'cli_prog_name': None, 'cli_use_class_docs_for_groups': False, 'enable_decoding': True, 'env_file': '.env', 'env_file_encoding': 'utf-8', 'env_ignore_empty': False, 'env_nested_delimiter': None, 'env_parse_enums': None, 'env_parse_none_str': None, 'env_prefix': '', 'extra': 'ignore', 'json_file': None, 'json_file_encoding': None, 'nested_model_default_partial_update': False, 'protected_namespaces': ('model_validate', 'model_dump', 'settings_customise_sources'), 'secrets_dir': None, 'toml_file': None, 'validate_default': True, 'yaml_file': None, 'yaml_file_encoding': None}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

flaretool.settings.get_settings()

flaretool.utills module

class flaretool.utills.DictToFieldConverter(dictionary)

Bases: object

This class converts a dictionary into field values.

Parameters:

dictionary (dict) – The dictionary to convert.

dictionary

The dictionary being converted.

Type:

dict

Raises:

AttributeError – If a requested field does not exist in the dictionary.

Example

# Create a dictionary dictionary = {‘name’: ‘John’, ‘age’: 30, ‘city’: ‘Tokyo’}

# Create an instance of DictToFieldConverter converter = DictToFieldConverter(dictionary)

# Access field values name = converter.name age = converter.age city = converter.city

print(name) # Output: ‘John’ print(age) # Output: 30 print(city) # Output: ‘Tokyo’

flaretool.utills.base64_convert(value: str, mode: Base64Mode = Base64Mode.ENCODE, encoding: str = 'utf-8') str

文字列のBase64エンコードまたはデコードを行います。

Parameters:
  • value (str) – エンコードまたはデコードする文字列

  • mode (Base64Mode, optional) – 処理モード. デフォルトはBase64Mode.ENCODE.

  • encoding (str, optional) – エンコードに使用する文字エンコーディング. デフォルトは’utf-8’.

Returns:

エンコードまたはデコード後の文字列

Return type:

str

Raises:

ValueError – 無効な処理モードが指定された場合

flaretool.utills.convert_value(value: str, mode: ConversionMode = ConversionMode.HALF_WIDTH, ascii=True, digit=True, kana=True, non_convert_chars=None) str

文字列を変換(半角/全角/大文字/小文字)

Parameters:
  • value (str) – 変換する文字列

  • mode (ConversionMode, optional) – 変換モード. デフォルトはConversionMode.HALF_WIDTH.

  • ascii (bool, optional) – ASCII文字の変換を有効にするかどうか. デフォルトはTrue.

  • digit (bool, optional) – 数字の変換を有効にするかどうか. デフォルトはTrue.

  • kana (bool, optional) – カナ文字の変換を有効にするかどうか. デフォルトはTrue.

  • non_convert_chars (str or list[str], optional) – 変換しない文字列. デフォルトはNone.

Returns:

変換後の文字列

Return type:

str

Raises:

ValueError – 無効な変換モードが指定された場合

flaretool.utills.get_temp_dir_path()

Get the path to a temporary dir path.

Returns:

The path to the temporary path.

Return type:

str

flaretool.utills.hash_value(value: str, mode: HashMode = HashMode.MD5, encoding: str = 'utf-8') str

文字列のハッシュ計算を行います。

Parameters:
  • value (str) – ハッシュ計算する文字列

  • mode (HashMode, optional) – ハッシュモード. デフォルトはHashMode.MD5.

  • encoding (str, optional) – 文字列のエンコーディング. デフォルトは’utf-8’.

Returns:

ハッシュ値の16進数表現

Return type:

str

Raises:

ValueError – 無効なハッシュモードが指定された場合

flaretool.utills.is_file_fresh(file_path: str, days: int) bool

Check if the given file has been modified within the specified number of days.

Parameters:
  • file_path (str) – The path to the file.

  • days (int) – The number of days to check for freshness.

Returns:

True if the file is fresh, False otherwise.

Return type:

bool

Module contents

flaretool python module [Terms of service](https://main.flarebrow.com/terms)

flaretool.check_version()
flaretool.get_latest_version() str
flaretool.get_lib_version()