From: Benjamin Braatz Date: Mon, 15 Jul 2019 09:53:57 +0000 (+0200) Subject: Add infrastructure to make project installable by pip. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=c2b02695d16b212287096454f75282e9f7ff0dd4;p=graphit%2Fgraph-client-py.git Add infrastructure to make project installable by pip. --- diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ea428a2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2019 Graph-IT GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4588af3 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Python Graph API + +This is a minimal Python API for the [Graph](https://graph-it.com/). +It works with Python 2 as well as Python 3. + +A more detailed documentation can be found in [doc/index.md](doc/index.md), +which can also be found at [http://docs.graph-it.com/graphit/graph-client-py](http://docs.graph-it.com/graphit/graph-client-py). diff --git a/doc/index.md b/doc/index.md index feedf61..0a79771 100644 --- a/doc/index.md +++ b/doc/index.md @@ -1,22 +1,17 @@ # Python Graph API -This is a minimal Python API for the Graph. +This is a minimal Python API for the [Graph](https://graph-it.com/). It works with Python 2 as well as Python 3. -## Prerequisites +## Installation -The Graph API uses [msgpack](https://msgpack.org/). -So, the Python binding for it has to be installed. - -For Debian-based distributions these can be done by: +The Python Graph API can be installed with `pip` directly from our git repository: ```sh -# apt install python-msgpack python3-msgpack +$ pip install git://git.graph-it.com/graphit/graph-client-py.git ``` -With pip, it can be done by: -```sh -# pip install msgpack -``` +The Graph API uses [msgpack](https://msgpack.org/). +So, the Python binding for it will be installed as a dependency. In order to use TLS connections to graphs, a client certificate chain has to be available in a file. @@ -58,3 +53,11 @@ The `test.py` script reads the configuration of a main graph from `config.json`, queries this main graph for remote graphs configured in it, prints a summary of all graph modules in the main graph and all remote graphs and downloads stationeries in all the graphs if they are configured there. + +## Plans + +Up to now, only a raw connection is implemented, +i.e., the Python implementation does not know anything about the actual API calls and just passes them to the graph server. + +We should add implementation and documentation for these actual API calls. +This would also allow to do at least some of the necessary conversions already in the library. diff --git a/graph.py b/graph.py deleted file mode 100644 index 4f03051..0000000 --- a/graph.py +++ /dev/null @@ -1,90 +0,0 @@ -from collections import OrderedDict -from socket import socket, AF_UNIX, AF_INET, SOCK_STREAM -from ssl import SSLContext, PROTOCOL_TLSv1 -from struct import pack, unpack -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse - -from msgpack import packb, unpackb - - -class Connection: - def __init__(self, url, crt_filename=''): - self.__url = url - self.__crt_filename = crt_filename - self.__cid = 0 - self.__sock = False - - def __del__(self): - if self.__sock: - self.__sock.close() - - def __init(self): - res = urlparse(self.__url) - if res.scheme == 'unix': - self.__sock = socket(AF_UNIX, SOCK_STREAM) - self.__sock.connect(res.path) - if res.scheme == 'tcp': - self.__sock = socket(AF_INET, SOCK_STREAM) - self.__sock.connect((res.hostname, res.port)) - if res.scheme == 'tls': - ssl_ctx = SSLContext(PROTOCOL_TLSv1) - ssl_ctx.load_cert_chain(self.__crt_filename) - self.__sock = socket(AF_INET, SOCK_STREAM) - self.__sock = ssl_ctx.wrap_socket(self.__sock) - self.__sock.connect((res.hostname, res.port)) - self.__read() - - def __read(self): - size = self.__sock.recv(4) - size = unpack('