Flask Extension for TuskLang Integration - Up to 59x Faster Template Rendering (Verified)
Project description
Flask-TSK 🚀
Revolutionary Flask Extension for TuskLang Integration
⚡ Performance Revolution
Flask-TSK enhances Flask with our Turbo Template Engine and full TuskLang SDK integration:
- Up to 23x faster template rendering for simple templates
- Up to 59x faster template rendering for complex templates
- 30,000+ renders per second vs 1,400 with standard Flask
- Intelligent caching and optimization for production workloads
- Full TuskLang SDK integration with configuration, functions, and operators
🚀 Quick Start
Installation
# Install Flask-TSK
pip install flask-tsk
# Or with performance optimizations
pip install flask-tsk[performance]
# Or install TuskLang Python SDK separately
pip install tusktsk>=2.0.3
📦 Dedicated Python Installation: https://py.tuskt.sk/
Basic Usage
from flask import Flask, render_template, jsonify
from tsk_flask import FlaskTSK
app = Flask(__name__)
tsk = FlaskTSK(app)
@app.route('/')
def index():
# Get configuration from TuskLang
app_name = tsk.get_config('app', 'name', 'Flask-TSK')
theme = tsk.get_config('ui', 'theme', 'light')
return render_template('index.html',
app_name=app_name,
theme=theme)
@app.route('/api/config')
def get_config():
# Return all configuration as JSON
return jsonify(tsk.get_all_sections())
@app.route('/execute/<function_name>')
def execute_function(function_name):
# Execute TuskLang functions dynamically
if function_name == 'format_date':
result = tsk.execute_function('@date.format', {'date': '2024-01-01', 'format': 'YYYY-MM-DD'})
elif function_name == 'math_add':
result = tsk.execute_function('@math.add', {'a': 5, 'b': 3})
else:
result = tsk.execute_function(function_name, {})
return jsonify({'function': function_name, 'result': result})
if __name__ == '__main__':
app.run(debug=True)
Template Integration
<!-- Get configuration values -->
<p>App Name: {{ tsk_config('app', 'name', 'Flask-TSK') }}</p>
<p>Theme: {{ tsk_config('ui', 'theme', 'light') }}</p>
<p>Database: {{ tsk_config('database', 'type', 'sqlite') }}</p>
<!-- Execute TuskLang functions -->
<p>Formatted Date: {{ tsk_function('@date.format', {'date': '2024-01-01', 'format': 'MMMM DD, YYYY'}) }}</p>
<p>Math Result: {{ tsk_function('@math.add', {'a': 10, 'b': 5}) }}</p>
<p>String Length: {{ tsk_function('@string.length', {'text': 'Hello TuskLang!'}) }}</p>
<!-- Parse TuskLang content -->
{% set parsed = tsk_parse('[app]\nname = "MyApp"\nversion = "1.0.0"') %}
<p>App Name: {{ parsed.app.name }}</p>
<p>Version: {{ parsed.app.version }}</p>
<!-- Stringify data to TuskLang format -->
{% set tsk_content = tsk_stringify({'theme': 'dark', 'debug': True}) %}
<pre>{{ tsk_content }}</pre>
<!-- Check TuskLang availability -->
{% if tsk_available %}
<p>✅ TuskLang is available (v{{ tsk_version }})</p>
{% else %}
<p>❌ TuskLang is not available</p>
{% endif %}
🎯 Advanced Features
Configuration Management
from tsk_flask import FlaskTSK
app = Flask(__name__)
tsk = FlaskTSK(app)
# Get configuration values with defaults
db_host = tsk.get_config('database', 'host', 'localhost')
db_port = tsk.get_config('database', 'port', 5432)
# Set configuration values
tsk.set_config('app', 'debug', True)
tsk.set_config('ui', 'theme', 'dark')
# Get entire sections
database_config = tsk.get_section('database')
security_config = tsk.get_section('security')
# Check if sections exist
if tsk.has_section('database'):
print("Database configuration found")
# Get all section keys
db_keys = tsk.get_all_keys('database')
Function Execution
# Execute TuskLang functions with arguments
result1 = tsk.execute_function('@math.add', {'a': 10, 'b': 20})
result2 = tsk.execute_function('@string.upper', {'text': 'hello world'})
result3 = tsk.execute_function('@date.format', {
'date': '2024-01-15',
'format': 'YYYY-MM-DD'
})
# Execute custom functions
custom_result = tsk.execute_function('utils', 'format_currency', {
'amount': 99.99,
'currency': 'USD'
})
Database Integration
# Get database configuration
db_config = tsk.get_database_config()
print(f"Database: {db_config.get('type', 'unknown')}")
print(f"Host: {db_config.get('host', 'localhost')}")
# Use in database connections
import psycopg2
db_config = tsk.get_database_config()
conn = psycopg2.connect(
host=db_config.get('host', 'localhost'),
port=db_config.get('port', 5432),
database=db_config.get('name', 'default'),
user=db_config.get('username'),
password=db_config.get('password')
)
Security Configuration
# Get security settings
security_config = tsk.get_security_config()
encryption_key = security_config.get('encryption_key')
jwt_secret = security_config.get('jwt_secret')
# Use in security operations
import jwt
jwt_secret = tsk.get_config('security', 'jwt_secret', 'default-secret')
token = jwt.encode({'user_id': 123}, jwt_secret, algorithm='HS256')
📊 Performance Benchmarks
| Feature | Flask Default | Flask-TSK | Improvement |
|---|---|---|---|
| Simple Template | 0.69ms | 0.03ms | 23x faster |
| Complex Template | 2.94ms | 0.05ms | 59x faster |
| Renders/Second | 1,454 | 30,167 | 21x more |
| Memory Usage | 100% | 85% | 15% reduction |
Benchmarks based on actual testing with 1000 iterations
🔥 Advanced Usage Examples
Performance Optimization
from flask_tsk import optimize_flask_app, render_turbo_template
# Apply all performance optimizations
optimize_flask_app(app)
# High-performance template rendering
result = render_turbo_template(template_content, context)
# Async rendering for concurrent operations
import asyncio
from flask_tsk import render_turbo_template_async
async def render_templates():
results = await asyncio.gather(*[
render_turbo_template_async(template, context)
for context in contexts
])
return results
TuskLang SDK Integration
from tsk_flask import FlaskTSK, parse, stringify, TSKParser
app = Flask(__name__)
tsk = FlaskTSK(app)
# Parse TuskLang content with advanced options
content = '''
[database]
type = "postgresql"
host = "localhost"
port = 5432
[security]
encryption_key = "your-secret-key"
jwt_secret = "jwt-secret"
'''
parsed = tsk.parse_tsk(content, enhanced=True)
print(f"Database type: {parsed['database']['type']}")
# Stringify data to TuskLang format
data = {
'app': {
'name': 'MyApp',
'version': '1.0.0',
'debug': True
},
'database': {
'type': 'sqlite',
'path': '/data/app.db'
}
}
tsk_content = tsk.stringify_tsk(data)
print(tsk_content)
# Create TuskLang parser instances
parser = tsk.create_parser()
storage = tsk.create_shell_storage()
API Endpoints
Flask-TSK provides comprehensive REST API endpoints:
# Get TuskLang status
curl http://localhost:5000/tsk/status
# Get configuration sections
curl http://localhost:5000/tsk/config/database
curl http://localhost:5000/tsk/config/security
# Get specific configuration values
curl http://localhost:5000/tsk/config/database/type
curl http://localhost:5000/tsk/config/database/host
# Set configuration values
curl -X POST http://localhost:5000/tsk/config/app/debug \
-H "Content-Type: application/json" \
-d 'true'
# Execute TuskLang functions
curl -X POST http://localhost:5000/tsk/function \
-H "Content-Type: application/json" \
-d '{
"section": "@math",
"key": "add",
"args": [10, 20]
}'
# Parse TuskLang content
curl -X POST http://localhost:5000/tsk/parse \
-H "Content-Type: application/json" \
-d '{
"content": "[app]\nname = \"MyApp\"",
"enhanced": true
}'
# Stringify data to TuskLang format
curl -X POST http://localhost:5000/tsk/stringify \
-H "Content-Type: application/json" \
-d '{
"data": {"theme": "dark", "debug": true}
}'
# Get all sections
curl http://localhost:5000/tsk/sections
# Check section existence
curl http://localhost:5000/tsk/sections/database/exists
# Get section keys
curl http://localhost:5000/tsk/sections/database/keys
# Delete sections
curl -X DELETE http://localhost:5000/tsk/sections/temp
# Get capabilities
curl http://localhost:5000/tsk/capabilities
📦 Installation Options
Basic Installation
pip install flask-tsk
With Performance Optimizations
pip install flask-tsk[performance]
With Database Support
pip install flask-tsk[databases]
With FastAPI Support
pip install flask-tsk[fastapi]
Development Installation
pip install flask-tsk[dev]
🔧 Configuration
Flask Configuration
app.config.update({
'TSK_CONFIG_PATH': '/path/to/config.tsk', # Custom config path
'TSK_AUTO_LOAD': True, # Auto-load peanu.tsk
'TSK_ENABLE_BLUEPRINT': True, # Enable API endpoints
'TSK_ENABLE_CONTEXT': True, # Enable template context
'TSK_ENABLE_FULL_SDK': True, # Enable full TuskLang SDK
})
TuskLang Configuration (peanu.tsk)
[database]
type = "postgresql"
host = "localhost"
port = 5432
name = "myapp"
username = "user"
password = "pass"
[security]
encryption_key = "your-encryption-key"
jwt_secret = "your-jwt-secret"
[ui]
theme = "dark"
component_cache = true
minify_assets = true
[utils]
format_date = "python:datetime.datetime.strptime(date, '%Y-%m-%d').strftime('%B %d, %Y')"
format_currency = "python:f'${amount:.2f}'"
🧪 Testing
Run Integration Tests
python test_integration.py
Performance Benchmark
python performance_benchmark.py
Demo Application
python test_example.py
📚 TuskLang Resources
Official TuskLang Resources
- TuskLang GitHub Repository - Main TuskLang project
- Python API Documentation - Complete Python SDK reference
- Python SDK Guide - Getting started with TuskLang in Python
- Dedicated Python Installation - Python-specific installation guide
- TuskLang Website - Official TuskLang website
TuskLang Features
- @ Operators - Powerful function execution system
- Cross-file References - Import and reference other TuskLang files
- Database Integration - Direct database queries and configuration
- Type Safety - Strong typing and validation
- Comments - Full comment support in configuration files
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
📄 License
MIT License - see LICENSE file for details.
🆘 Support
- Documentation: https://flask-tsk.readthedocs.io/
- Issues: https://github.com/cyber-boost/flask-tsk/issues
- Discussions: https://github.com/cyber-boost/flask-tsk/discussions
🔗 Related Projects
- TuskLang - The revolutionary TuskLang language
- tusktsk - Official TuskLang Python SDK
- TuskLang Python API - Complete Python API documentation
- TuskLang Python SDK Guide - Python SDK getting started guide
Flask-TSK - Making Flask faster than Django, more powerful than ever, and ready to revolutionize Python web development! 🚀
Powered by TuskLang - The future of configuration and automation.
Project details
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 flask_tsk-1.2.0.tar.gz.
File metadata
- Download URL: flask_tsk-1.2.0.tar.gz
- Upload date:
- Size: 240.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bce0150f5f194f0700ed34b483ef3b507499010c62fe0bd4e1c4c9e4b8b322c
|
|
| MD5 |
a05125da4bcf59b39b0b8cfbdf403d60
|
|
| BLAKE2b-256 |
ebb10f5b0e1ae7d7f54bd962f8f5dc26bff3b0e733797ede48c9c433afc87a64
|
File details
Details for the file flask_tsk-1.2.0-py3-none-any.whl.
File metadata
- Download URL: flask_tsk-1.2.0-py3-none-any.whl
- Upload date:
- Size: 245.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88a3899dd76157a1dc5e8fe2dbbcd22e9a7fcae0c742769d30af80ee81a548e8
|
|
| MD5 |
731f2559c8c98215b707281f992c34e9
|
|
| BLAKE2b-256 |
830c25a756d8815f9b7fa7fc5b5096678842ef8dea347f450425d7e8df98fb2d
|