PyOuroboros: Difference between revisions
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
./setup.py install | ./setup.py install | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Basic Usage | |||
import the Ouroboros dev library: | |||
<syntaxhighlight lang="Python"> | |||
from ouroboros.dev import * | |||
</syntaxhighlight> | |||
On the server side, Accepting a flow: | |||
<syntaxhighlight lang="Python"> | |||
f = flow_accept() | |||
</syntaxhighlight> | |||
returns a new allocated flow object. | |||
Client side: Allocating a flow to a certain name: | |||
<syntaxhighlight lang="Python"> | |||
f = flow_alloc("name") | |||
</syntaxhighlight> | |||
returns a new allocated Flow object. | |||
Broadcast: | |||
<syntaxhighlight lang="Python"> | |||
f = flow_join("name") | |||
</syntaxhighlight> | |||
returns a new allocated Flow object to a broadcast layer. | |||
When a flow is not needed anymore, it can be deallocated: | |||
<syntaxhighlight lang="Python"> | |||
f.dealloc() | |||
</syntaxhighlight> | |||
To avoid having to call dealloc(), you can also use the with statement: | |||
<syntaxhighlight lang="Python"> | |||
with flow_alloc("dst") as f: | |||
f.writeline("line") | |||
print(f.readline()) | |||
</syntaxhighlight> | |||
After the flow is deallocated, it is not readable or writeable anymore. | |||
<syntaxhighlight lang="Python"> | |||
f.alloc("name") | |||
</syntaxhighlight> | |||
will allocate a new flow for an existing Flow object. | |||
To read / write from a flow: | |||
f.read(count) # read up to _count_ bytes and return bytes | |||
f.readline(count) # read up to _count_ characters as a string | |||
f.write(buf, count) # write up to _count_ bytes from buffer | |||
f.writeline(str, count) # write up to _count_ characters from string |
Revision as of 18:25, 8 June 2022
This page is under construction
The python API allows you to write Ouroboros-native programs in Python (>=3.4) is available as a separate repository. You need Ouroboros installed before installing PyOuroboros. To download and install PyOuroboros(virtual environment recommended)
$ git clone https://ouroboros.rocks/git/pyouroboros
# Or github mirror:
# git clone https://github.com/dstaesse/pyouroboros
$ cd pyouroboros
./setup.py install
Basic Usage
import the Ouroboros dev library:
from ouroboros.dev import *
On the server side, Accepting a flow:
f = flow_accept()
returns a new allocated flow object.
Client side: Allocating a flow to a certain name:
f = flow_alloc("name")
returns a new allocated Flow object.
Broadcast:
f = flow_join("name")
returns a new allocated Flow object to a broadcast layer.
When a flow is not needed anymore, it can be deallocated:
f.dealloc()
To avoid having to call dealloc(), you can also use the with statement:
with flow_alloc("dst") as f:
f.writeline("line")
print(f.readline())
After the flow is deallocated, it is not readable or writeable anymore.
f.alloc("name")
will allocate a new flow for an existing Flow object.
To read / write from a flow:
f.read(count) # read up to _count_ bytes and return bytes f.readline(count) # read up to _count_ characters as a string f.write(buf, count) # write up to _count_ bytes from buffer f.writeline(str, count) # write up to _count_ characters from string