← Back to Alpanzo

Local Sync Setup Guide

Follow these steps to sync your Alpanzo data to a local folder on your computer using a Python server and an ngrok tunnel.

Prerequisites

Step 1: Install Python Libraries

Open your terminal or command prompt and install the necessary Python libraries:

pip install Flask Flask-Cors

Step 2: Create the Python Server Script

Create a new file named alpanzo_server.py and paste the following code into it. This script will create a simple web server to handle your data.

import os
import json
from flask import Flask, request, jsonify, send_from_directory
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

DATA_DIR = "alpanzo_data"
PASSWORD = "alpanzo_secure"  # Change this to your own password!

if not os.path.exists(DATA_DIR):
    os.makedirs(DATA_DIR)

def check_auth():
    if not PASSWORD: return True
    auth_header = request.headers.get('Authorization')
    return auth_header == f"Bearer {PASSWORD}"

@app.route('/files/<filename>', methods=['GET'])
def get_file(filename):
    if not check_auth(): return jsonify({"error": "Unauthorized"}), 401
    filepath = os.path.join(DATA_DIR, filename)
    return send_from_directory(DATA_DIR, filename) if os.path.exists(filepath) else (jsonify({"error": "File not found"}), 404)

@app.route('/files/<filename>', methods=['POST'])
def save_file(filename):
    if not check_auth(): return jsonify({"error": "Unauthorized"}), 401
    content = request.get_json()
    filepath = os.path.join(DATA_DIR, filename)
    with open(filepath, 'w', encoding='utf-8') as f:
        json.dump(content, f, indent=2)
    return jsonify({"success": True}), 200

@app.route('/files/test-connection', methods=['GET', 'POST', 'OPTIONS'])
def test_connection():
    if request.method == 'OPTIONS': return jsonify({"status": "ok"}), 200
    if not check_auth(): return jsonify({"error": "Unauthorized"}), 401
    return jsonify({"status": "ok"}), 200

if __name__ == '__main__':
    print(f"Alpanzo Local Sync Server running.\nPassword: {PASSWORD}\nData will be stored in '{DATA_DIR}'.\nListening on http://127.0.0.1:5000")
    app.run(host='127.0.0.1', port=5000)

Step 3: Run the Local Server

In your terminal, navigate to the directory where you saved alpanzo_server.py and run it:

python alpanzo_server.py

You should see a message that the server is running. Keep this terminal window open.

Step 4: Expose with ngrok

Open a new terminal window. Navigate to where you downloaded ngrok and run the following command to expose your local server to the internet:

./ngrok http 5000

Note: On Windows, you might just run ngrok http 5000.

ngrok will display a public URL, which looks something like https://random-string.ngrok-free.app. Copy this HTTPS URL.

Step 5: Connect Alpanzo

Now, in the Alpanzo application:

  1. Go to Settings (Ctrl + ,).
  2. Navigate to the Data tab.
  3. Find the Local Sync section.
  4. Paste your public ngrok URL (the one you copied) into the "ngrok Tunnel URL" input field.
  5. Enter your password (default is alpanzo_secure).
  6. Click Connect Local Sync.

If successful, the button will turn red and say "Disconnect". Your data will now automatically save to the alpanzo_data folder on your computer!