Integration

Integration with Python Projects

FlowLang can be embedded in Python applications for scriptable automation.

Example: Flask Integration

from flask import Flask, request
from flowlang.lexer import Lexer
from flowlang.parser import Parser
from flowlang.interpreter import Interpreter

app = Flask(__name__)

@app.route('/execute', methods=['POST'])
def execute_flowlang():
    code = request.json.get('code')
    
    tokens = Lexer(code).tokens
    ast = Parser(tokens).parse()
    Interpreter().eval(ast)
    
    return {'status': 'success'}

Integration with CI/CD Pipelines

Use FlowLang scripts in continuous integration workflows.

Example: GitHub Actions

name: Run FlowLang Script
on: [push]
jobs:
  run-script:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Setup Python
        uses: actions/setup-python@v2
      - name: Install FlowLang
        run: pip install flowlang
      - name: Execute Script
        run: flow run scripts/deploy.flow

Integration with Docker

Create containerized FlowLang execution environments.

Dockerfile Example:

FROM python:3.9-slim

WORKDIR /app

RUN pip install flowlang

COPY scripts/ /app/scripts/

CMD ["flow", "run", "scripts/main.flow"]

Integration with Scheduling Systems

Use with cron or systemd timers for scheduled execution.

Cron Example:

# Run daily report at 9 AM
0 9 * * * /usr/local/bin/flow run /home/user/reports/daily.flow

Integration with FastAPI

Create REST APIs that execute FlowLang scripts.

from fastapi import FastAPI, HTTPException
from flowlang.lexer import Lexer
from flowlang.parser import Parser
from flowlang.interpreter import Interpreter

app = FastAPI()

@app.post("/run")
async def run_script(code: str):
    try:
        tokens = Lexer(code).tokens
        ast = Parser(tokens).parse()
        result = Interpreter().eval(ast)
        return {"status": "success", "result": str(result)}
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))

Integration with Django

Use FlowLang for background tasks in Django applications.

from django.http import JsonResponse
from flowlang.lexer import Lexer
from flowlang.parser import Parser
from flowlang.interpreter import Interpreter

def execute_script(request):
    if request.method == 'POST':
        code = request.POST.get('code')
        
        tokens = Lexer(code).tokens
        ast = Parser(tokens).parse()
        Interpreter().eval(ast)
        
        return JsonResponse({'status': 'success'})
    
    return JsonResponse({'error': 'Invalid method'}, status=405)

Integration with AWS Lambda

Deploy FlowLang scripts as serverless functions.

import json
from flowlang.lexer import Lexer
from flowlang.parser import Parser
from flowlang.interpreter import Interpreter

def lambda_handler(event, context):
    code = event.get('code', '')
    
    try:
        tokens = Lexer(code).tokens
        ast = Parser(tokens).parse()
        result = Interpreter().eval(ast)
        
        return {
            'statusCode': 200,
            'body': json.dumps({'result': str(result)})
        }
    except Exception as e:
        return {
            'statusCode': 500,
            'body': json.dumps({'error': str(e)})
        }

Integration with Celery

Use FlowLang for distributed task processing.

from celery import Celery
from flowlang.lexer import Lexer
from flowlang.parser import Parser
from flowlang.interpreter import Interpreter

app = Celery('tasks', broker='redis://localhost:6379')

@app.task
def execute_flowlang_script(code):
    tokens = Lexer(code).tokens
    ast = Parser(tokens).parse()
    result = Interpreter().eval(ast)
    return str(result)

Integration with Jupyter Notebooks

Execute FlowLang code within Jupyter notebooks.

from flowlang.lexer import Lexer
from flowlang.parser import Parser
from flowlang.interpreter import Interpreter

def run_flowlang(code):
    tokens = Lexer(code).tokens
    ast = Parser(tokens).parse()
    return Interpreter().eval(ast)

# Use in notebook cell
code = """
let data = http_get("https://api.github.com")
print data
"""

run_flowlang(code)

Best Practices for Integration

  • Always validate and sanitize FlowLang code before execution
  • Use try-except blocks to handle execution errors gracefully
  • Consider running FlowLang scripts in isolated environments
  • Monitor resource usage for long-running scripts
  • Implement proper logging for debugging and auditing
  • Set timeouts for HTTP requests to prevent hanging