diff options
author | Dimitri Staessens <[email protected]> | 2021-02-14 17:42:22 +0100 |
---|---|---|
committer | Dimitri Staessens <[email protected]> | 2021-02-14 17:42:22 +0100 |
commit | 20df52a54fc03ef067cb4bce3e176e19129b4a84 (patch) | |
tree | 191014dce7f5ae907cee22f6e38dd2207590e7d4 /content/en/blog/news/20200507-python.md | |
parent | c279eee663c376e9f9f032057e247eaf6023c203 (diff) | |
download | website-20df52a54fc03ef067cb4bce3e176e19129b4a84.tar.gz website-20df52a54fc03ef067cb4bce3e176e19129b4a84.zip |
content: Move releases to docs and add 0.18 notes
Diffstat (limited to 'content/en/blog/news/20200507-python.md')
-rw-r--r-- | content/en/blog/news/20200507-python.md | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/content/en/blog/news/20200507-python.md b/content/en/blog/news/20200507-python.md deleted file mode 100644 index d4b3504..0000000 --- a/content/en/blog/news/20200507-python.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -date: 2020-05-07 -title: "A Python API for Ouroboros" -linkTitle: "Python" -description: "Python" -author: Dimitri Staessens ---- - -Support for other programming languages than C/C++ has been on my todo -list for quite some time. The initial approach was using -[SWIG](http://www.swig.org), but we found the conversion always -clunky, it didn't completely work as we wanted to, and a while back we -just decided to deprecate it. Apart from C/C++ we only had a [rust -wrapper](https://github.com/chritchens/ouroboros-rs). - -Until now! I finally took the time to sink my teeth into the bindings -for Python. I had some brief looks at the -[ctypes](https://docs.python.org/3/library/ctypes.html) library a -while back, but this time I looked into -[cffi](https://cffi.readthedocs.io/en/latest/) and I was amazed at how -simple it was to wrap the more difficult functions that manipulate -blocks of memory (flow\_read, but definitely the async fevent() call). -And now there is path towards a 'nice' Python API. - -Here is a taste of what the -[oecho](https://ouroboros.rocks/cgit/ouroboros/tree/src/tools/oecho/oecho.c) -tool looks like in Python: - -```Python -from ouroboros import * -import argparse - - -def client(): - f = flow_alloc("oecho") - f.writeline("Hello, PyOuroboros!") - print(f.readline()) - f.dealloc() - - -def server(): - print("Starting the server.") - while True: - f = flow_accept() - print("New flow.") - line = f.readline() - print("Message from client is " + line) - f.writeline(line) - f.dealloc() - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='A simple echo client/server') - parser.add_argument('-l', '--listen', help='run as a server', action='store_true') - args = parser.parse_args() - if args.listen is True: - server() - else: - client() -``` - -I have more time in the next couple of days, so I expect this to be -released after the weekend. - -Oh, and here is a picture of Ouroboros load-balancing between the C (top right) -and Python (top left) implementations using the C and Python clients: - -{{<figure width="60%" src="/blog/news/20200507-python-lb.png">}} - -Can't wait to get the full API done! - -Cheers, - -Dimitri |