蓝图属性图模型接口的python版本

pyblueprints的Python项目详细描述


概要:提供了一个层,用于从使用的图形数据库系统中抽象python开发人员

遵循Tinkerpop为蓝图提供的一组接口, 这个proyect旨在给python开发人员提供类似的功能。 定义了一组抽象类,以指导 不同图形数据库引擎的实现。

功能

这是一个实验版本,只允许部分功能:

在尝试此库之前,请记住备份您的数据。

安装

在您的virtualenv中安装pyBlueprints的最简单方法是:

pip install pyblueprints

用法

此版本的pybluerprints允许您通过rexster实例或neo4j rest客户机api连接到图形数据库。因此,可以使用这两个选项访问neo4j数据库,尽管neo4j事务模式只能通过后者使用。 Rexster实例还提供到以下数据库的连接:

  • TinkerGraph
  • OrientDB
  • DEX
  • Sail RDF Stores

雷克斯特

连接到Rexster实例

>>> from pyblueprints import RexsterServer, RexsterGraph
>>> #Connecting to server
>>> HOST = 'http://localhost:8182'
>>> server = RexsterServer(HOST)
>>> #List graphs availbale in server
>>> server.graphs()
[u'tinkergraph', u'gratefulgraph', u'tinkergraph-readonly', u'sailgraph', u'emptygraph']
>>> #Connecting to a given graph
>>> graph = RexsterIndexableGraph(server, 'tinkergraph')

neo4j rest客户端

通过neo4j rest客户机api创建一个图形对象

>>> from pyblueprints.neo4j import Neo4jGraph
>>> graph = Neo4jGraph('http://localhost:7474/db/data')

通过neo4j rest客户机api创建可索引图形对象

>>> from pyblueprints.neo4j import Neo4jIndexableGraph
>>> graph = Neo4jIndexableGraph('http://localhost:7474/db/data')
可用的类是:
  • Neo4J图形
  • neo4jindexablegraph
  • NEO4J传输图
  • neo4jTransactionAlindexableGraph

代码示例

添加/删除顶点

>>> vertex = graph.addVertex()
>>> graph.removeVertex(vertex)

添加/删除边

>>> v1 = graph.addVertex()
>>> v2 = graph.addVertex()
>>> newEdge = graph.addEdge(v1, v2, 'myLabel')
>>> graph.removeEdge(newEdge)

顶点方法

>>> graph= Neo4jGraph(HOST)
>>> v1 = graph.addVertex()
>>> v2 = graph.addVertex()
>>> newEdge = graph.addEdge(v1, v2, 'myLabel')
>>> vertex = graph.getVertex(_id)
>>> # get methods return a generator function
>>> edge = list(vertex.getBothEdges())[0]
>>> edge = list(vertex.getOutEdges())[0]
>>> edges = list(vertex.getInEdges())

顶点/边属性

>>> vertex_id = vertex.getId()
>>> vertex.setProperty('name', 'paquito')
>>> print vertex.getPropertyKeys()
>>> print vertex.getProperty('name')
>>> vertex.removeProperty('name')

边缘方法

>>> outVertex = edge.getOutVertex()
>>> inVertex = edge.getInVertex()
>>> print getLabel()

添加/删除手动索引

>>> index = graph.createManualIndex('myManualIndex', 'vertex')
>>> graph.dropIndex('myManualIndex', 'vertex')

索引方法
>>> index = graph.getIndex('myManualIndex', 'vertex')
>>> vertex = graph.addVertex()
>>> index.put('key1', 'value1', vertex)
>>> print index.count('key1', 'value1')
>>> print index.getIndexName()
>>> print index.getIndexClass()
>>> print index.getIndexType()
>>> # get returns a generator function
>>> vertex2 = list(index.get('key1', 'value1'))[0]
>>> index.remove('key1', 'value1', vertex)

事务性方法
>>> graph= Neo4jTransactionalGraph(HOST)
>>> graph.startTransaction()
>>> v = graph.addVertex()
# Stoping calls the commit
>>> graph.stopTransaction()
>>> vertexId = v.getId()
>>> v = graph.getVertex(vertexId)
>>> graph.startTransaction()
>>> v.setProperty('p1', 'v1')
>>> graph.stopTransaction()

更改

0.6.0(2012-02-27)

  • neo4j rest client 1.6支持的测试新事务

0.5.1(2011-11-13)

  • 事务重构将管理委托给restclient

0.5(2011-07-26)

  • 添加了事务操作支持
  • 为Neo4J API添加了DropIndex功能
  • 在文档中添加了代码示例
  • 添加测试

0.3.2(2011-07-15)

  • 错误修复

0.3.1(2011-07-14)

  • 修复了RemoveProperty错误

0.3(2011-07-12)

  • 添加了单元测试
  • 添加了getedge、removeproperty和getbothedges方法
  • 在notfounderrors中返回none而不是引发异常
  • 错误修复

0.2.2(2011-07-11)

  • 添加了基本安装和使用文档

0.2.1(2011-07-06)

  • 更新的文档

0.2(2011-07-06)

  • 增加了与python rexster的集成

0.1(2011-06-29)

  • 首次发布python索引包。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java提高机器学习Rest服务性能   java反转字符的字符串顺序,并使用构造函数将其放入LinkedList   继承为什么Java不支持在方法签名中添加“throws”?   执行DDL alter table if exists任务时发生java错误。城市   java在eclipse中使用CREATETXT并打包在jar中   java AES256与3DES 256密钥检测   具有两个相同类型字段的java JPA实体   java Webapp日志记录设置被忽略   java KeyEventDispatcher可以在一个应用程序中工作,但不能在另一个应用程序中工作   带有Swing和OpenJDK的java PinchZoom   未涉及java AspectJ注释切入点(对于任何注释类型)   java如何在FuseBAI中获取日志文件详细信息   java在Linux上将wstring转换为jstring