Skip to content

JAWAD-ASGHAR/VarSync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VarSync - Cross-Language Variable Sharing System

VarSync is a lightweight, real-time variable sharing system that allows Python and JavaScript (Node.js) processes on the same machine to share variables through a Go core backend.

Architecture

┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│   Python    │    │   Node.js   │    │     Go      │
│  Wrapper    │    │  Wrapper    │    │    Core     │
│             │    │             │    │             │
│ set_var()   │    │ setVar()    │    │ In-Memory   │
│ get_var()   │    │ getVar()    │    │ Key-Value   │
│ delete_var()│    │ deleteVar() │    │   Store     │
│ list_vars() │    │ listVars()  │    │             │
└─────────────┘    └─────────────┘    └─────────────┘
       │                   │                   │
       └───────────────────┼───────────────────┘
                           │
                    TCP/Unix Socket
                    JSON Protocol

Features

  • Real-time variable sharing between Python and Node.js processes
  • Lightweight Go core with in-memory key-value store
  • Concurrent access with proper locking mechanisms
  • Cross-platform support (Linux, macOS, Windows)
  • Simple JSON protocol for communication
  • Automatic connection management and error handling
  • Support for primitive data types (strings, numbers, booleans)
  • JSON serialization for complex objects

Quick Start

1. Start the Go Core

cd core
go build -o varsync
./varsync

The core will start listening on localhost:8080 by default.

2. Python Usage

from varbridge import VarSync

# Connect to the core
vs = VarSync()

# Set variables
vs.set_var("user_count", 42)
vs.set_var("status", "active")
vs.set_var("data", {"name": "John", "age": 30})

# Get variables
count = vs.get_var("user_count")  # 42
status = vs.get_var("status")     # "active"
data = vs.get_var("data")         # {"name": "John", "age": 30}

# List all keys
keys = vs.list_vars()  # ["user_count", "status", "data"]

# Delete a variable
vs.delete_var("status")

3. Node.js Usage

const VarSync = require('varbridge-js');

// Connect to the core
const vs = new VarSync();

// Set variables
vs.setVar("user_count", 42);
vs.setVar("status", "active");
vs.setVar("data", {name: "John", age: 30});

// Get variables
const count = vs.getVar("user_count");  // 42
const status = vs.getVar("status");     // "active"
const data = vs.getVar("data");         // {name: "John", age: 30}

// List all keys
const keys = vs.listVars();  // ["user_count", "status", "data"]

// Delete a variable
vs.deleteVar("status");

Installation

Go Core

cd core
go build -o varsync

Python Wrapper

cd varbridge-py
pip install -e .

Node.js Wrapper

cd varbridge-js
npm install

Examples

See the examples/ directory for complete working examples:

  • examples/python_node_example.py - Python example
  • examples/node_python_example.js - Node.js example
  • examples/cross_language_demo.py - Cross-language demonstration

Protocol

The communication protocol uses JSON messages over TCP:

Request Format

{
  "cmd": "SET|GET|DELETE|LIST_KEYS",
  "key": "variable_name",
  "value": "variable_value"
}

Response Format

{
  "status": "success|error",
  "data": "response_data",
  "error": "error_message"
}

Development

Project Structure

VarSync/
├── core/                 # Go core implementation
├── varbridge-py/         # Python wrapper
├── varbridge-js/         # Node.js wrapper
├── examples/             # Usage examples
└── README.md

Building from Source

  1. Go Core: cd core && go build -o varsync
  2. Python: cd varbridge-py && pip install -e .
  3. Node.js: cd varbridge-js && npm install

License

MIT License - see LICENSE file for details.

About

VarSync is a lightweight, real-time variable sharing system that allows different processes environments on the same machine to share variables through a Go core backend.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors