This is a utility library for Python.
License | |
Environment | |
Technology | |
pyproject.toml
fileAdd the following to your pyproject.toml
file.
[tool.poetry.dependencies]
nglcobdai-utils = {git = "https://github.com/nglcobdai/nglcobdai_utils.git", tag = "v0.1.0"}
Then run the following command.
$ poetry lock
Required libraries are as follows.
Refer to the pyproject.toml
file for the latest version.
Library | Version |
---|---|
pydantic | ^1.8.2 |
python | ^3.10 |
pydantic-settings | ^2.4.0 |
pytz | ^2024.1 |
pyyaml | ^6.0.2 |
slack-sdk | ^3.32.0 |
Settings
class is a utility class that reads the settings from the .env
file.
.env
file in the root directory of your project..env
file.PROJECT_NAME=hoge
Settings
class to read the settings.from nglcobdai_utils import Settings
settings = Settings()
print(settings.PROJECT_NAME)
Logger
class is a utility class that creates a logger object.
log_file
is optional. If you want to log to a file, you can specify the file path.
Logger
class to create a logger object.from nglcobdai_utils import get_logger
logger = get_logger(name=__name__, log_file="app.log")
logger.debug('This is a debug message.')
logger.info('This is an info message.')
logger.warning('This is a warning message.')
logger.error('This is an error message.')
app.log
will be created in the root directory of your project.
Slack
class is a utility class that sends messages to Slack.
Refer to the how to create a Slack App for more information.
Slack
class to send messages to Slack.token
is the Bot User OAuth Access Token that you got when you created a Slack App.
from nglcobdai_utils import Slack
slack = Slack(token="xoxb-xxxxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxxxx")
slack.post_text(channel="general", text="Hello, World!") # Send a text message
slack.post_file(channel="general", files=[{"file": "README.md", "title": "README.md"}]) # Send a file