A very Usefull API-Framework for All-Type Python Projects
Project description
ToolOS SDK
A lightweight Python app framework with inheritance-based architecture, multi-language support, and modular design.
📚 Documentation
🌐 Complete Documentation: https://claytechnologie.github.io/ToolSDK/
Quick Links for more information:
Installation
pip install toolos
Getting Started
This guide will help you get started with ToolOS SDK and build your first application.
Your First ToolOS Application
1. Create a Settings File and SDK
First, create a settings.json file to configure your application:
{
"version": "1.0.0",
"language": "en",
"cachepath": "data/cache",
"temppath": "data/temp",
"logpath": "data/logs",
"languagepath": "data/lang"
}
Then, initialize the SDK in your application:
{
"version": "1.0.0",
"name": "MyApp",
"settings_path": "settings.json",
"standard_language_library": true
}
or as a dictionary in your code:
sdk = {
"version": "1.0.0",
"name": "MyApp",
"settings_path": "settings.json",
"standard_language_library": True
}
app = MyApp(**sdk)
...
2. Application Usages
Create your main application file:
# app.py
import toolos as engine
class MyApp(engine.Api):
def __init__(self):
super().__init__("settings.json")
self.Helper # Helper Class Function
self.Log # Log Class Function
self.Cache # Cache Class Function
self.Temp # Temp Class Function
self.Settings # Settings Class Function
self.StateMachine # StateMachine Class Function
self.Language # Language Class Function
self.Utils # Utils Class Function
3. Short API Usage
ToolOS SDK includes several built-in functionalities for smooth and efficient app development.
Language Management:
import toolos as api
class YourApp(api.Api):
def __init__(self, settings_path="settings.json", standard_language_library=True):
# standard_language_library = True Enables loading built-in language files (en, de, fr, ru, ...)
super().__init__(settings_path, standard_language_library)
self.Language # Language Class Function
# Reading Language Files
self.Language.GetAvailableLanguages()
# Reading Language UsageKeys for a specific language
self.Language.GetAllTranslationKeys(lang="de")
# Returns: list: ['key1', 'key2', ...] for language "de"
# Reading Language UsageKeys for current language
self.Language.GetAllTranslationKeys()
# Returns: list: ['key1', 'key2', ...] for current language
# Translate Texts
print(self.Language.Translate("settings")) # Dynamic Translates to current language (settings.json)
# Prints "Einstellungen" if current language is "de" or "Settings" if current language is "en"
# Adding a own translationpackage
# Add a specific language package
de_lang = "/data/lang/de_extras.json"
fr_lang = "/data/lang/fr_extras.json"
en_lang = "/data/lang/en_extras.json"
# Adding language packages
self.Language.AddLanguagePackage("de", de_lang)
self.Language.AddLanguagePackage("fr", fr_lang)
self.Language.AddLanguagePackage("en", en_lang)
# Reaload Language Instance
self.Language.Reload()
# Now the new keys are available
print(self.Language.Translate("new_key")) # Dynamic Translates to current language (new_key from de_extras.json)
# Prints "Neuer Schlüssel" if current language is "de" or "New Key
Example language package (de/fr/... .json)
Example de.json:
{
"new_key": "Neuer Schlüssel",
"another_key": "Ein weiterer Schlüssel",
"header": "Überschrift"
}
Or ru.json:
{
"new_key": "Новый ключ",
"another_key": "Еще один ключ",
"header": "Заголовок"
}
4. State Management
Use the state machine to control application flow:
import toolos as engine
class YourApp(engine.Api):
def __init__(self, settings_path="settings.json", standard_language_library=True):
super().__init__(settings_path, standard_language_library)
self.StateMachine.AddKeyState("mods", False) # Adding a key state "mods" with default value False # Use this together with Settings.Global("mods_enabled", False) like:
mods = self.Settings.Global("mods_enabled", False)
self.StateMachine.SetKeyState("mods", mods)
# The StateMachine automatically starts with "FIRST_ENTRY" state
while self.StateMachine.IsRunning: # IsRunning is always True unless you stop it
if self.StateMachine.IsState(self.StateMachine.FIRST_ENTRY):
# Your logic for FIRST_ENTRY state
# Transition to MAINMENU state
self.StateMachine.SetState(self.StateMachine.MAINMENU)
elif self.StateMachine.IsState(self.StateMachine.MAINMENU):
# Your logic for MAINMENU state
# Transition to STEP_1 state
self.StateMachine.SetState(self.StateMachine.STEP_1)
elif self.StateMachine.IsState(self.StateMachine.ERROR):
# Your logic for ERROR state
self.StateMachine.SetState(self.StateMachine.EXIT) # Transition to EXIT state
elif self.StateMachine.IsState(self.StateMachine.EXIT):
# Your logic for EXIT state
self.StateMachine.Stop() # Stop the state machine loop
elif self.StateMachine.KeyStateIs("mods", key=True):
# Your logic when "mods" key state is True. If mods doesnt exist or is False, it will always return False
pass
5. Settings Management
Handle application settings dynamically:
import toolos as engine
class YourApp(engine.Api):
def __init__(self, settings_path="settings.json", standard_language_library=True):
super().__init__(settings_path, standard_language_library)
yourneed = self.Settings.Global("yourneed", "default_value")
# Returning "default_value" if "yourneed" is not set in settings.json
# else returns the value of your key "yourneed"
# Practical Example:
if mods_enabled := self.Settings.Global("mods_enabled", False):
self.StateMachine.SetKeyState("mods", mods_enabled)
else:
self.StateMachine.SetKeyState("mods", mods_enabled)
# Check if settings were updated and reload if necessary
if self.Settings.CheckIfUpdate():
self.Settings.Update()
Caching System
Efficiently manage temporary data:
class YourApp(engine.Api):
def __init__(self, settings_path="settings.json", standard_language_library=True):
super().__init__(settings_path, standard_language_library)
import json
preferences = {
"theme": "dark",
"font_size": 14,
"show_tips": True
}
cachepath = self.Settings.Global("cachepath", "/")
cachename = self.Settings.Global("cachename", "example.cache")
# Write a cache file
self.Cache.WriteCacheFile(f"{cachepath}{cachename}", json.dumps(preferences))
# Read cache file
if self.Cache.CacheExists(f"{cachepath}{cachename}"):
data = self.Cache.ReadCacheFile(f"{cachepath}{cachename}")
preferences = json.loads(data)
Temporary File Management
Manage temporary files easily:
# Write temp file
self.Temp.WriteTempFile("user_prefs.json", json.dumps(preferences))
# Read temp file
if self.Temp.TempExists("user_prefs.json"):
data = self.Temp.ReadTempFile("user_prefs.json")
preferences = json.loads(data)
Logging Management
Keep track of application events:
# Log different types of events
self.Log.WriteLog("app.log", "User logged in")
self.Log.WriteLog("error.log", f"Error: {str(exception)}")
self.Log.WriteLog("debug.log", f"Processing item {item_id}")
Next Steps
- Explore the API Reference for detailed documentation
- Check out Examples for more complex use cases
- Learn about creating mods and extensions
- Read the Contributing Guide to contribute to ToolOS SDK
Best Practices
- Always initialize with settings file: Use a proper
settings.jsonconfiguration - Handle language changes: Implement
Language.Reload()for dynamic language switching and use 'lang.json' files for translations - Use state machine: Organize your application flow with the built-in state machine
- Log important events: Use the logging system for debugging and monitoring
- Clean up temporary files: Use
Temp.RemoveTempFile()to manage temporary data
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toolos-2.2.0.tar.gz.
File metadata
- Download URL: toolos-2.2.0.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
837135dd3ae780dc9b43bd3e277dd639fb0c58ce584e136c3cc9db6365f7b0d4
|
|
| MD5 |
85251e2001195e01acb4517f250fa1f9
|
|
| BLAKE2b-256 |
83d461f25624b5eee24f442b30d91fe75bd43dce47f75fd2afca6ffd4e9791ef
|
File details
Details for the file toolos-2.2.0-py3-none-any.whl.
File metadata
- Download URL: toolos-2.2.0-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e76d3a57849c641cadbbe0ace80392d63bdaefc180adfb91e3591b9f0fccd87
|
|
| MD5 |
c28fc44d59e4a1d0b4998ae297e41dd0
|
|
| BLAKE2b-256 |
02ad5a52c640e5c8b4fa527fb7fe25f5942deb0f5e18589c9574b97737ad4edf
|