Skip to main content

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

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"
}

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

  1. Always initialize with settings file: Use a proper settings.json configuration
  2. Handle language changes: Implement Language.Reload() for dynamic language switching and use 'lang.json' files for translations
  3. Use state machine: Organize your application flow with the built-in state machine
  4. Log important events: Use the logging system for debugging and monitoring
  5. 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

toolos-2.0.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toolos-2.0.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file toolos-2.0.0.tar.gz.

File metadata

  • Download URL: toolos-2.0.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for toolos-2.0.0.tar.gz
Algorithm Hash digest
SHA256 ecb2453201cccbfa15e97b9c0b12b5ae5b949928a9e631edb96672eb51767ba0
MD5 eedf63d40d6cca899c2f6230a14c323d
BLAKE2b-256 4d0401ff49d486932ab02a854976fad862349927f5e5a8edd6cfa3d0de7544b2

See more details on using hashes here.

File details

Details for the file toolos-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: toolos-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for toolos-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c733009e2e6dd8f78ec125e7b22106e82b04f9ed88c229445805418ca6e5b31
MD5 6cabdc37ed42d34765f88d50aa0f9ec3
BLAKE2b-256 f9406754f287d77c2b431bc2a46b8a8a9431dd6785fb6d484fa84ceb0f884b94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page