kiarina-utils-app
English | 日本語
Dependencies
| Package | Version | License |
|---|---|---|
| platformdirs | >=4.10.0 |
MIT |
| filelock | >=3.19.1 |
MIT |
| Pydantic | >=2.11.7 |
MIT |
| pydantic-settings | >=2.10.1 |
MIT |
| pydantic-settings-manager | >=3.2.0 |
MIT |
Installation
pip install kiarina-utils-app
Features
- Configuring the application identity Set the application name and author once at startup, used as the namespace for directories and locks.
- Resolving user directories
Resolve user-specific cache, config, and data directories, honoring
XDG_*environment variables and platform defaults. - Controlling single instance Prevent duplicate application instances using an OS-level advisory file lock.
Configuring the application identity
Call configure() once when the application starts.
The name and author can each be set only once; reconfiguring raises AppAlreadyConfiguredError, and accessing them before configuration raises AppNotConfiguredError (use reset() to clear them in tests).
from kiarina.utils.app import configure
configure(
app_name="kiapi",
app_author="kiarina",
)
Resolving user directories
The user_directory service returns user-specific directories as Path objects.
from kiarina.utils.app import user_directory
cache_dir = user_directory.get_user_cache_dir()
config_dir = user_directory.get_user_config_dir()
data_dir = user_directory.get_user_data_dir()
The resolution order is:
- An explicit override from settings (
~is expanded to the home directory). - The
XDG_*environment variable (XDG_CACHE_HOME/XDG_CONFIG_HOME/XDG_DATA_HOME), joined with the app name, when set. XDG takes priority on all platforms, including macOS. - The platform default for the running user (via platformdirs).
The settings can be overridden with environment variables:
| Environment variable | Description |
|---|---|
KIARINA_UTILS_APP_USER_CACHE_DIR |
Override the user cache directory. |
KIARINA_UTILS_APP_USER_CONFIG_DIR |
Override the user config directory. |
KIARINA_UTILS_APP_USER_DATA_DIR |
Override the user data directory. |
Controlling single instance
The single_instance service prevents duplicate instances using a lock file under the user cache directory.
The lock is an OS-level advisory lock, so it is released automatically when the process exits.
from kiarina.utils.app import single_instance
from kiarina.utils.app import AlreadyRunningError
try:
single_instance.acquire()
except AlreadyRunningError:
raise SystemExit("Another instance is already running.")
try:
... # run the application
finally:
single_instance.release()
API Reference
kiarina.utils.app
from kiarina.utils.app import (
app,
App,
configure,
reset,
single_instance,
user_directory,
AppSettings,
settings_manager,
AlreadyRunningError,
AppAlreadyConfiguredError,
AppNotConfiguredError,
)
app and App
class App:
app_name: str
app_author: str
app: App
The shared application identity configured by configure().
configure
def configure(app_name: str, app_author: str) -> None: ...
Set the application identity once at startup. The name and author are used as the namespace for user directories and lock files.
Parameters
app_name(str): Application name.app_author(str): Application author.
Raises
AppAlreadyConfiguredError: The name or author has already been set.
reset
def reset() -> None: ...
Clear the configured application name and author. Intended for use in tests.
single_instance
The single_instance service module prevents duplicate instances using an OS-level advisory lock file placed under the user cache directory.
def acquire(*, timeout: float = 10.0) -> None: ...
def release() -> None: ...
acquireattempts to take the lock, waiting up totimeoutseconds, and raisesAlreadyRunningErrorif another instance already holds it.releasereleases the lock if it is currently held.
Parameters
timeout(float): Maximum seconds to wait for the lock (default:10.0).
Raises
AlreadyRunningError: Another instance already holds the lock.
user_directory
The user_directory service module resolves user-specific directories as Path objects, honoring settings overrides, XDG_* environment variables, and platform defaults in that order.
def get_user_cache_dir() -> Path: ...
def get_user_config_dir() -> Path: ...
def get_user_data_dir() -> Path: ...
Returns
Path: The resolved user cache, config, or data directory.
Raises
AppNotConfiguredError: The application name or author has not been configured (when falling back to platform defaults).
AppSettings
class AppSettings(BaseSettings):
user_cache_dir: str | None = None
user_config_dir: str | None = None
user_data_dir: str | None = None
Pydantic settings model for directory overrides. Reads environment variables with the prefix KIARINA_UTILS_APP_.
Fields
user_cache_dir(str | None): Override for the user cache directory (default:None).user_config_dir(str | None): Override for the user config directory (default:None).user_data_dir(str | None): Override for the user data directory (default:None).
settings_manager
settings_manager: SettingsManager[AppSettings]
Global settings manager instance for AppSettings, provided by pydantic-settings-manager. Access the active settings via settings_manager.settings.
from kiarina.utils.app import settings_manager
settings_manager.user_config = {
"user_cache_dir": "~/.cache/kiapi",
}
Exceptions
class AppNotConfiguredError(RuntimeError): ...
class AppAlreadyConfiguredError(RuntimeError): ...
class AlreadyRunningError(RuntimeError): ...
| Exception | Raised when |
|---|---|
AppNotConfiguredError |
The application name or author is accessed before being configured. |
AppAlreadyConfiguredError |
configure() is called after the name or author has already been set. |
AlreadyRunningError |
single_instance.acquire() fails because another instance holds the lock. |
Metadata
Release files for kiarina-utils-app 2.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kiarina_utils_app-2.4.0.tar.gz | 10.0 kB | With provenance | Details for kiarina_utils_app-2.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kiarina_utils_app-2.4.0-py3-none-any.whl | Python 3 | none | any | Details for kiarina_utils_app-2.4.0-py3-none-any.whl |
Total release size: 18.6 kB
Release files / kiarina_utils_app-2.4.0.tar.gz
| Download URL | kiarina_utils_app-2.4.0.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a2cd291e17534b746429f7ec0904e46ea4a5e9083997a99f7876abd38015e3e
|
|
BLAKE2b-256 checksum How to use checksums |
f234bf751c50693b2046b4279082da1d96217119c53fa9d512ba4d72478a6537
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.
Transparency logRelease files / kiarina_utils_app-2.4.0-py3-none-any.whl
| Download URL | kiarina_utils_app-2.4.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ebd1b413b0e1a08d2f3b291692762f1ea99649c99d91d3a0495bbf10ac40c48
|
|
BLAKE2b-256 checksum How to use checksums |
d4bff913ee9ff4110c6d2af30084a8b0730e47d8270156f4333c673d0dd36bee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.
Transparency logSecurity for kiarina-utils-app 2.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for kiarina_utils_app-2.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.