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:

Installation

pip install toolos

Getting Started

This guide will help you get started with ToolOS SDK and build your first application.

Installation

Install ToolOS SDK via pip:

pip install toolos

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",
  "mods_enabled": true,                     # Optional
  "cachepath": "data/cache",
  "temppath": "data/temp",
  "logpath": "data/logs",
  "languagepath": "data/lang"
}

2. Basic Application Structure

Create your main application file:

# app.py
import toolos as engine

class MyApp(engine.Api):
    def __init__(self):
        super().__init__("settings.json")
        self.isRunning = False
        
    def Run(self):
        # Welcome message in current language  
        welcome = self.Language.Translate("welcome")
        print(welcome)
        
        # Set application state
        self.StateMachine.SetState(self.StateMachine.MAINMENU)
        
        # Log application start
        self.Log.WriteLog("app.log", "Application started")
        
        # Cache some data
        self.Cache.WriteCacheFile("session.txt", "Session started")
        
        while self.isRunning:
            if self.StateMachine.IsState(self.StateMachine.MAINMENU):
                self.ShowMainMenu()
            elif self.StateMachine.IsState(self.StateMachine.EXIT):
                break
                
    def ShowMainMenu(self):
        print("=== " + self.Language.Translate("header") + " ===")
        print("1. " + self.Language.Translate("settings"))
        print("2. " + self.Language.Translate("exit"))
        
        choice = input(self.Language.Translate("input"))
        if choice == "2":
            self.StateMachine.SetState(self.StateMachine.EXIT)
        
        # Log application start
        self.Log.WriteLog("app.log", "Application started")

        # Cache some data
        self.Cache.WriteCacheFile("session.txt", "Session started")

if __name__ == "__main__":
    app = MyApp()
    app.run()

3. Multi-Language Support

ToolOS SDK includes built-in translations for 7 languages. To use them: ToolOS also includes an own package system for custom translations.

# Get available languages
languages = self.Language.GetAvailableLanguages()
print(f"Available languages: {languages}")


# Add custom language package.  For example 'add_to_cart' translation
self.Language.AddLanguagePackage(lang="en", path="en_extra_translations.json")
self.Language.AddLanguagePackage(lang="de", path="de_extra_translations.json")
self.Language.Reload()

# Translate text
greeting = self.Language.Translate("welcome")
settings = self.Language.Translate("settings")
exit_msg = self.Language.Translate("add_to_cart")  # From custom package

4. State Management

Use the state machine to control application flow:

# Define application states
if self.StateMachine.IsState(self.StateMachine.FIRST_ENTRY):
    # First time running
    self.setup_application()
    self.StateMachine.SetState(self.StateMachine.MAINMENU)

elif self.StateMachine.IsState(self.StateMachine.MAINMENU):
    # Show main menu
    self.show_main_menu()

elif self.StateMachine.IsState(self.StateMachine.EXIT):
    # Exit application
    self.cleanup_and_exit()

5. Settings Management

Handle dynamic settings changes:

# Check if settings were updated
if self.Settings.CheckIfUpdate():
    # Reload settings
    self.Settings.Update()

    # Reload language if changed
    self.Language.Reload()

    print(self.Language.Translate("settings_updated"))

Advanced Features

Custom Language Packages

Add custom translations for your application:

# Add custom language package
self.Language.AddLanguagePackage("en", "my_translations.json")

Caching System

Efficiently manage temporary data:

# Write cache file
self.Cache.WriteCacheFile("user_prefs.json", json.dumps(preferences))

# Read cache file
if self.Cache.CacheExists("user_prefs.json"):
    data = self.Cache.ReadCacheFile("user_prefs.json")
    preferences = json.loads(data)

Logging

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
  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-1.5.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

toolos-1.5.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for toolos-1.5.2.tar.gz
Algorithm Hash digest
SHA256 d5e4e013f946befb11cb1de4b4815c97bc9168002f1b86dc6862e4578afcef26
MD5 e183b56dba5bf4dee1c15a5e4bcd636d
BLAKE2b-256 ce01a8788fe3745f9cc4608ab06b7b137ea2931c23f3f071ec8bbb27419ee506

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for toolos-1.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be0a9d9ed8f8795037dd0970805760b2b02d9898f6164e26283ce4150443099a
MD5 10fe90a4045cdd7c68b00cac08a0e095
BLAKE2b-256 a97fe51b08327f4ee8d0958f1062d72943f3a3cc6cbd162962f184ce4e068090

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