Create an entanglement across network and even programming language.
Project description
# Entangle-Python [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
Did you ever think syncing variables between two processes (anywhere in the world) is difficult?
Entangle-Python is your solution.
It enables you to entangle two variables across processes.
One needs to launch an entanglement server and one an entanglement client.
You can connect entanglements even cross programming language.
You can see the documentation below or simply look at some examples.
A python server and client in one script can be found [here](https://github.com/penguinmenac3/entangle-python/blob/master/example.py).
If you want only a server to which for example [entangle-js](https://github.com/penguinmenac3/entangle-js) can connect to, check out [this script](https://github.com/penguinmenac3/entangle-python/blob/master/example_server.py).
## Install
Simply pip install the package.
```bash
pip install entangle-python
```
## Usage
### Entanglement Server
Listen for entanglement requests and handle them.
Inside the callback you can do whatever you want, it is a new thread and does not hinder new entanglements from happening.
Note that an entanglement object corresponds to a client.
```python
import entangle
# Define a callback for every new entanglement
def on_entangle(entanglement):
def rprint(x):
print(x)
entanglement.test = x
entanglement.rprint = rprint
# Listen for entanglements (listenes in blocking mode)
entangle.listen(host="localhost", port=12345, password="42", callback=on_entangle)
```
### Entanglement Client
If your script wants to connect to an entanglement server use the following.
The connect function connects asynchronously to a server.
Once an entanglement is established your callback gets called.
```python
import entangle
def on_entangle(entanglement):
entanglement.remote_fun("rprint")("Hello Universe!")
entanglement.close()
# asynchronously connect to a client (entanglement spawns a daemon thread)
entangle.connect(host="localhost", port=12345, password="42", callback=on_entangle)
```
Did you ever think syncing variables between two processes (anywhere in the world) is difficult?
Entangle-Python is your solution.
It enables you to entangle two variables across processes.
One needs to launch an entanglement server and one an entanglement client.
You can connect entanglements even cross programming language.
You can see the documentation below or simply look at some examples.
A python server and client in one script can be found [here](https://github.com/penguinmenac3/entangle-python/blob/master/example.py).
If you want only a server to which for example [entangle-js](https://github.com/penguinmenac3/entangle-js) can connect to, check out [this script](https://github.com/penguinmenac3/entangle-python/blob/master/example_server.py).
## Install
Simply pip install the package.
```bash
pip install entangle-python
```
## Usage
### Entanglement Server
Listen for entanglement requests and handle them.
Inside the callback you can do whatever you want, it is a new thread and does not hinder new entanglements from happening.
Note that an entanglement object corresponds to a client.
```python
import entangle
# Define a callback for every new entanglement
def on_entangle(entanglement):
def rprint(x):
print(x)
entanglement.test = x
entanglement.rprint = rprint
# Listen for entanglements (listenes in blocking mode)
entangle.listen(host="localhost", port=12345, password="42", callback=on_entangle)
```
### Entanglement Client
If your script wants to connect to an entanglement server use the following.
The connect function connects asynchronously to a server.
Once an entanglement is established your callback gets called.
```python
import entangle
def on_entangle(entanglement):
entanglement.remote_fun("rprint")("Hello Universe!")
entanglement.close()
# asynchronously connect to a client (entanglement spawns a daemon thread)
entangle.connect(host="localhost", port=12345, password="42", callback=on_entangle)
```
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for entangle_python-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8111a87e7c74af9261a4061f4a6f19598e4ae8da28eddce6c16646b2e8f2487c |
|
MD5 | 9f1f4db9e3f3bc143aa2caaa5574e815 |
|
BLAKE2b-256 | aabb6a10cfbd6710af2d58b130f9f9a452f5045e5bdd62360b755c73d66fc522 |