|
1 | | -# JanusGraph Python driver |
2 | | - |
3 | | -## License |
4 | | - |
5 | | -JanusGraph Python driver code is provided under the [Apache 2.0 |
6 | | -license](APACHE-2.0.txt) and documentation is provided under the [CC-BY-4.0 |
7 | | -license](CC-BY-4.0.txt). For details about this dual-license structure, please |
8 | | -see [`LICENSE.txt`](LICENSE.txt). |
| 1 | +# JanusGraph-Python |
| 2 | + |
| 3 | +JanusGraph-Python extends Apache TinkerPop™'s [Gremlin-Python][gremlinpython] with |
| 4 | +support for [JanusGraph][janusgraph]-specific types. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +To connect to JanusGraph Server, a `DriverRemoteConnection` instance needs to be |
| 9 | +created and configured with a message serializer that adds support for |
| 10 | +JanusGraph specific types. |
| 11 | + |
| 12 | +This can be done like this for GraphSON 3: |
| 13 | + |
| 14 | +```python |
| 15 | +from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection |
| 16 | +from janusgraph_python.driver.serializer import JanusGraphSONSerializersV3d0 |
| 17 | + |
| 18 | +connection = DriverRemoteConnection( |
| 19 | + 'ws://localhost:8182/gremlin', 'g', |
| 20 | + message_serializer=JanusGraphSONSerializersV3d0()) |
| 21 | +``` |
| 22 | + |
| 23 | +Note that the client should be disposed on shut down to release resources and |
| 24 | +to close open connections with `connection.close()`. |
| 25 | +The connection can then be used to configure a `GraphTraversalSource`: |
| 26 | + |
| 27 | +```python |
| 28 | +from gremlin_python.process.anonymous_traversal import traversal |
| 29 | + |
| 30 | +g = traversal().with_remote(connection) |
| 31 | +# Reuse 'g' across the application |
| 32 | +``` |
| 33 | + |
| 34 | +The `GraphTraversalSource` `g` can now be used to spawn Gremlin traversals: |
| 35 | + |
| 36 | +```python |
| 37 | +hercules_age = g.V().has("demigod", "name", "hercules").values("age").next() |
| 38 | +print(f"Hercules is {hercules_age} years old.") |
| 39 | +``` |
| 40 | + |
| 41 | +Refer to the chapter [Gremlin Query Language][gremlin-chapter] in the |
| 42 | +JanusGraph docs for an introduction to Gremlin and pointers to further |
| 43 | +resources. |
| 44 | +The main syntactical difference for Gremlin-Python is that it follows Python naming |
| 45 | +conventions, e.g., method names use snake_case instead of camelCase. Other difference is that when Python reserved words (e.g. "is") overlap with Gremlin steps or tokens, those gets underscore suffix (e.g. "is_"). |
| 46 | + |
| 47 | +### Text Predicates |
| 48 | + |
| 49 | +The `Text` class provides methods for |
| 50 | +[full-text and string searches][text-predicates]: |
| 51 | + |
| 52 | +```python |
| 53 | +from janusgraph_python.process.traversal import Text |
| 54 | + |
| 55 | +g.V().has("demigod", "name", Text.text_prefix("herc")).to_list() |
| 56 | +``` |
| 57 | + |
| 58 | +The other text predicates can be used the same way. |
| 59 | + |
| 60 | +## Version Compatibility |
| 61 | + |
| 62 | +The lowest supported JanusGraph version is 1.0.0. |
| 63 | +The following table shows the supported JanusGraph versions for each version |
| 64 | +of JanusGraph-Python: |
| 65 | + |
| 66 | +| JanusGraph-Python | JanusGraph | |
| 67 | +| ----------------- | ---------------------- | |
| 68 | +| 1.0.z | 1.0.z | |
| 69 | + |
| 70 | +While it should also be possible to use JanusGraph-Python with other versions of |
| 71 | +JanusGraph than mentioned here, compatibility is not tested and some |
| 72 | +functionality (like added Gremlin steps) will not work as it is not supported |
| 73 | +yet in case of an older JanusGraph version or was removed in a newer JanusGraph |
| 74 | +version. |
| 75 | + |
| 76 | +## Serialization Formats |
| 77 | + |
| 78 | +JanusGraph-Python supports GraphSON 3 only. GraphBinary is not yet |
| 79 | +supported. |
| 80 | + |
| 81 | +Not all of the JanusGraph-specific types are already supported by the formats: |
| 82 | + |
| 83 | +| Format | RelationIdentifier | Text predicates | Geoshapes | Geo predicates | |
| 84 | +| ----------- | ------------------ | --------------- | --------- | -------------- | |
| 85 | +| GraphSON3 | x | x | - | - | |
| 86 | +| GraphBinary | - | - | - | - | |
| 87 | + |
| 88 | +## Community |
| 89 | + |
| 90 | +JanusGraph-Python uses the same communication channels as JanusGraph in general. |
| 91 | +So, please refer to the |
| 92 | +[_Community_ section in JanusGraph's main repository][janusgraph-community] |
| 93 | +for more information about these various channels. |
| 94 | + |
| 95 | +Please use GitHub issues only to report bugs or request features. |
| 96 | + |
| 97 | +## Contributing |
| 98 | + |
| 99 | +Please see |
| 100 | +[`CONTRIBUTING.md` in JanusGraph's main repository][janusgraph-contributing] |
| 101 | +for more information, including CLAs and best practices for working with |
| 102 | +GitHub. |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +JanusGraph-Python code is provided under the [Apache 2.0 license](APACHE-2.0.txt) |
| 107 | +and documentation is provided under the [CC-BY-4.0 license](CC-BY-4.0.txt). For |
| 108 | +details about this dual-license structure, please see |
| 109 | +[`LICENSE.txt`](LICENSE.txt). |
| 110 | + |
| 111 | +[janusgraph]: https://janusgraph.org/ |
| 112 | +[gremlinpython]: https://tinkerpop.apache.org/docs/current/reference/#gremlin-python |
| 113 | +[gremlin-chapter]: https://docs.janusgraph.org/getting-started/gremlin/ |
| 114 | +[text-predicates]: https://docs.janusgraph.org/interactions/search-predicates/#text-predicate |
| 115 | +[janusgraph-community]: https://github.com/JanusGraph/janusgraph#community |
| 116 | +[janusgraph-contributing]: https://github.com/JanusGraph/janusgraph/blob/master/CONTRIBUTING.md |
0 commit comments