Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
gh-981: Cleanup gafferpy
Browse files Browse the repository at this point in the history
  • Loading branch information
t92549 committed Jun 15, 2022
1 parent 3b26700 commit 65c038a
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 151 deletions.
127 changes: 33 additions & 94 deletions python-shell/README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
# Deprecated
<img align="right" width="200" height="auto" src="https://github.com/gchq/Gaffer/raw/develop/logos/logo.png">

The python-shell, or gafferpy, has been [deprecated](https://github.com/gchq/gaffer-tools/issues/951) as of 24/11/21. We plan to delete it at some point in the Gaffer 2 release process. This is because gafferpy is being replaced by fishbowl for Gaffer 2 graphs. Before Gaffer 2.0.0's full release, fishbowl will be updated to work with Gaffer 2 and have all the missing functionality added to it. Therefore, in the future, you should use fishbowl for interacting with Gaffer 2 graphs and gafferpy for Gaffer 1 graphs.
## Python shell
# Gaffer Python Client

This python shell connects to a Gaffer REST API and requires Python 3.x See [gaffer-tools/python-shell](https://github.com/gchq/gaffer-tools/tree/master/python-shell).
![ci](https://github.com/gchq/gaffer-tools/actions/workflows/continuous-integration.yaml/badge.svg)
[<img src="https://img.shields.io/badge/docs-passing-success.svg?logo=readthedocs">](https://gchq.github.io/gaffer-doc/latest/)

To start using the python shell you will need an instance of the REST API running. You can start the Gaffer road-traffic-demo rest server and ui \(see ui/README.md\) using the command:
## Features

- Persistently connect to a Gaffer rest api to run operations
- Connect using PKI certificates and SSL
- Generate Python client code for custom Operations, Predicates, Binary Operators and Functions
- Stream results back

## Installation

Gafferpy requires Python 3.6+. We don't currently release gafferpy on pypi, but you can install it over ssh with:

```bash
./ui/example/road-traffic/scripts/start.sh
pip install git+https://github.com/gchq/gaffer-tools.git#subdirectory=python-shell
```

Once this is running you can run the python example by using the command \(all commands are run from the root of the python-shell project\):
Or if you have the source code locally and want any changes you make reflected in your installation, you can go to the python-shell directory and run:

```bash
python3 src/example.py
python3 src/example_map.py
pip install -e .
```

Alternatively if you have you own REST API running that is authenticated with PKI certificates then you can follow the pki example. Before using the example you will need to export your PKI certificate into a .pem file:
## Quick Start

The python shell connects to a running Gaffer REST API. You can start the Gaffer road-traffic-demo rest server and [ui](../ui/README.md) using the command:

```bash
python3 src/example_pki.py
python3 src/example_map_pki.py
./ui/example/road-traffic/scripts/start.sh
```

To use the python shell without installing just ensure you are execute your scripts from within the python-shell directory. To connect to gaffer you will need to do something like this:

```python
# Import the client library and connector
from gafferpy import gaffer as g
from gafferpy import gaffer_connector
gc = gaffer_connector.GafferConnector("http://localhost:8080/rest/latest")
```

To fetch the Gaffer schema you can then run:

```python
result = gc.execute_get(g.GetSchema())

print('Schema:')
print(result)
print()
```
# Instantiate a connector
gc = gaffer_connector.GafferConnector("http://localhost:8080/rest/latest")

You can run an operation like this:
# You can use the connector to perform get requests
schema = gc.execute_get(g.GetSchema())

```python
# And also run operations
elements = gc.execute_operation(
operation=g.GetAllElements()
)
```

Multiple operations like this:

```python
# Multiple operations
elements = gc.execute_operations(
operations=[
g.GetAllElements(),
g.Limit(result_limit=3)
]
)
```

And an operation chain like this:

```python
# And operation chains
elements = gc.execute_operation_chain(
operation_chain=g.OperationChain(
operations=[
Expand All @@ -80,69 +74,14 @@ elements = gc.execute_operation_chain(

See [operation examples](https://gchq.github.io/gaffer-doc/v1docs/getting-started/operations/contents) for more examples of operations in python.

### Installation

We currently don't release gafferpy on pypi, but there are plently of ways to use it once you have the source code.
As well as refering to the Python source files as above, you can also build gafferpy from source (useful for distribution) or install a local copy in develop mode that will update when you change the source code.

#### Build with bdist_wheel

This option builds gafferpy and puts the binaries in `python-shell/dist` where it can then be distributed and installed with `pip install`.

Compilation of the project requires the wheel package, this can be installed using pip:

```bash
pip3 install wheel
```

The project can then be compiled by running the following command from the root of the python-shell project:

```bash
python3 setup.py bdist_wheel
```

This creates a distributable Python wheel which can installed locally to provide the Gaffer Python shell to other applications.

The wheel file is install using pip:

```bash
pip3 install dist/gafferpy-<gaffer.version>-py2.py3-none-any.whl
```

#### Developer installation

Alternatively, if you want to just install gafferpy locally and have any code changes you make to it reflected in your installation, you can go to the python-shell directory and run:

```bash
pip3 install -e .
```
Note that this does not install the dependencies, which can be found in the `requirements.txt`, and installed with:
```bash
pip3 install -r requirements.txt
```


#### Import
After either installation, the shell can be imported into an application from anywhere as below:

```python
from gafferpy import gaffer as g
from gafferpy import gaffer_connector
gc = gaffer_connector.GafferConnector("http://localhost:8080/rest/latest")
```

### Testing

We have some unit and integration tests for our python shell. To run all of the tests, first deploy the REST API \(UI will also be deploy\):
## Testing

```bash
# To run all of the tests, first deploy the road traffic example
./ui/example/road-traffic/scripts/start.sh
```

then from within the python-shell folder run:

```bash
python3 -m unittest discover
# Then from within the python-shell folder run
python -m unittest discover
```

## License
Expand Down
14 changes: 6 additions & 8 deletions python-shell/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3"
"Programming Language :: Python :: 3.0",
"Programming Language :: Python :: 3.1",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries :: Python Modules",
]
install_requires = []
python_requires = ">3.6"
install_requires = [
"requests>=2.4.0"
]

###############################################################################

Expand Down Expand Up @@ -81,5 +78,6 @@ def find_meta(meta):
zip_safe=False,
classifiers=classifiers,
install_requires=install_requires,
python_requires=python_requires,
py_modules=['gafferpy.gafferpy', 'gafferpy.example']
)
11 changes: 0 additions & 11 deletions python-shell/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
__version__ = "2.0.0-alpha-0.2"

__title__ = "gafferpy"
__description__ = "Gaffer Python Shell"
__uri__ = "https://github.com/gchq/gafferpy-tools"
__doc__ = __description__ + " <" + __uri__ + ">"

__author__ = "GCHQ"

__license__ = "Apache 2.0"
__copyright__ = "Crown Copyright (c) 2016-2017"
11 changes: 11 additions & 0 deletions python-shell/src/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__version__ = "2.0.0-alpha-0.2"

__title__ = "gafferpy"
__description__ = "Gaffer Python Shell"
__uri__ = "https://github.com/gchq/gafferpy-tools"
__doc__ = __description__ + " <" + __uri__ + ">"

__author__ = "GCHQ"

__license__ = "Apache 2.0"
__copyright__ = "Crown Copyright (c) 2016-2017"
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 0 additions & 36 deletions python-shell/src/fromJson.py

This file was deleted.

2 changes: 1 addition & 1 deletion python-shell/src/test/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import unittest

import example
from examples import example


class ExampleTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion python-shell/src/test/test_example_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import unittest

import example_map
from examples import example_map


class ExampleMapTest(unittest.TestCase):
Expand Down

0 comments on commit 65c038a

Please sign in to comment.