精华内容
下载资源
问答
  • py2neo-py2neo-2.0.tar.gz

    2021-04-08 18:26:09
    泪崩,最新的镜像都删除了,好不容易找到了老版py2neo,供大家学习分享。仅供学习使用,侵权联系我删除
  • py2neo-py2neo-2.0.2.tar.gz

    2021-04-08 18:26:56
    泪崩,最新的镜像都删除了,好不容易找到了老版py2neo,供大家学习分享。仅供学习使用,侵权联系我删除
  • py2neo-py2neo-2.0.1.tar.gz

    2021-04-08 18:26:31
    泪崩,最新的镜像都删除了,好不容易找到了老版py2neo,供大家学习分享。仅供学习使用,侵权联系我删除
  • py2neo-py2neo-2.0.8.tar.gz

    2021-04-08 18:20:34
    泪崩,最新的镜像都删除了,好不容易找到了这个py2neo 2.0 版本,供大家学习分享。仅供学习使用,侵权联系我删除
  • The Py2neo v4 Handbook 安装 需求 py2neo.data – Data Types 1.1 Node and Relationship objects 1.2 Subgraph objects 1.3 Path objects and other Walkable types 1.4 Record objects 1.5 Table objects...

    目录

     

    The Py2neo v4 Handbook

    安装

    需求

    py2neo.data – Data Types

    1.1 Node and Relationship objects

    1.2 Subgraph objects

    1.3 Path objects and other Walkable types

    1.4 Record objects

    1.5 Table objects


    The Py2neo v4 Handbook

    Py2neo是一个客户端库和工具箱,用于从Python应用程序和命令行使用Neo4j。该库同时支持Bolt和HTTP,并提供高级API、OGM、管理工具、交互式控制台、用于Pygments的Cypher lexer和许多其他功能。与以前的版本不同,Py2neo v4不再需要支持http的服务器,可以完全通过Bolt工作。

    安装

    要安装py2neo的最新稳定版本,只需使用pip:

    $ pip install --upgrade py2neo

    要安装最新的py2neo预发行版,请使用带有——pre标志的pip:

    $ pip install --upgrade --pre py2neo

    需求

    The following versions of Python and Neo4j are supported:

    Python 2.7 / 3.4 / 3.5 / 3.6 / 3.7

    Neo4j 3.2 / 3.3 / 3.4 / 3.5 (推荐每个版本的最新版本)

    虽然可以使用Neo4j Community或Enterprise edition,但py2neo不提供对企业特性的直接支持,比如因果集群。

    还要注意,Py2neo是在Linux下使用标准CPython发行版开发和测试的。虽然其他操作系统和Python发行版也可以工作,但对它们的支持不可用。

    1. py2neo.data – Data Types

    为方便起见,py2neo.data的成员。还可以直接从py2neo导入数据。

    Py2neo提供了一组丰富的数据类型,用于处理基于图的数据和基于记录的数据。图形类型与Neo4j完全兼容,但也可以独立使用。它们包括基本实体、节点和关系以及表示这些实体集合的类。

    图数据类被设计成使用标准操作协同工作,最明显的是集合操作。这些操作的详细信息将在关于Subgraph对象、Path对象和其他Walkable类型的部分中介绍。

    1.1 Node and Relationship objects

    Neo4j使用的标记属性图模型的两个基本构建块是节点关系。节点是图中数据存储的基本单元。它可以包含一组键值对(属性),还可以选择添加一个或多个文本标签。关系是一对节点之间的有类型的定向连接(或者是单个节点上的循环)。与节点一样,关系也可能包含一组属性。

    下面的代码展示了如何创建两个节点以及连接它们的关系。每个节点都有一个属性名称,并标记为Person。关系ab描述了从第一个节点a到第二个节点b的连接。

    >>> from py2neo.data import Node, Relationship
    
    >>> a = Node("Person", name="Alice")
    
    >>> b = Node("Person", name="Bob")
    
    >>> ab = Relationship(a, "KNOWS", b)
    
    >>> ab
    
    (Alice)-[:KNOWS]->(Bob)
    
    class py2neo.data.Node(*labels, **properties)

    使用指定的标签和属性构造一个新的节点对象。在初始状态下,节点是未绑定的。这意味着它只存在于客户机上,不引用相应的服务器节点。节点通常通过在Neo4j数据库中创建来绑定。

    node == other

    如果节点和其他值相等,则返回True。节点相等仅基于它所表示的远程节点的ID;属性和标签都没有考虑到相等性。这意味着如果绑定,则节点对象只能被视为与绑定到同一远程节点的另一个节点对象相等。如果一个节点没有绑定,因此没有相应的节点ID,那么它只能等于它自己。

    node != other

    True如果节点不相等,则返回。

    hash(node)

    根据节点的对象ID(如果未绑定)或它表示的远程节点的ID(如果绑定)返回节点的哈希。

    node[key]

    使用键key或缺少键返回节点的属性值。None

    node[key] = value

    的属性值设置节点与关键的关键,以价值或者删除该属性值是None。

    del node[key]

    从node中删除带有key key的属性,如果不存在这样的属性,则引发a 。KeyError

    len(node)

    返回node中的属性数。

    dict(node)

    返回node中所有属性的字典。

    walk(node)

    Yield 节点是中的唯一项walk()。

    node.labels

    返回与node关联的完整标签集。此集合是不可变的,不能用于添加或删除标签。

    node.has_label(label)

    True如果节点具有标签label,则返回。

    node.add_label(label)

    将标签标签添加到node。

    node.remove_label(label)

    从节点除去标签标签,如果不存在,则引发一个ValueError

    node.clear_labels()

    删除节点上的所有标签。

    node.update_labels(label)

    从可迭代标签向节点添加多个标签。

     

    在类型为type的一对节点之间(或一个节点与其自身之间)构造关系。如果未指定类型,则默认为T0。可以通过扩展Relationship该类来覆盖此默认值:

    >>> c = Node("Person", name="Carol")
    
    >>> class WorksWith(Relationship): pass
    
    >>> ac = WorksWith(a, c)
    
    >>> type(ac)
    'WORKS_WITH'

     

    relationship == other

    True如果关系和其他相等,则返回。关系相等性基于开始节点,结束节点和关系类型的相等性(上面描述了节点相等性)。这意味着,相同节点之间相同类型的任何两个关系始终被视为相等。请注意,此行为与Neo4j本身略有不同,Neo4j允许在相同节点之间使用相同类型的多个关系。

    relationship != other

    True如果关系不相等,则返回。

    hash(relationship)

    根据其开始节点,结束节点和类型返回关系的哈希。

    relationship[key]

    返回与键key或如果缺少键的关系的属性值。None

    relationship[key] = value

    的属性值设置关系与键键到值或者删除属性值是None。

    del relationship[key]

    从关系中删除带有key key的属性,如果不存在这样的属性,则引发a 。KeyError

    len(relationship)

    返回关系中的属性数。

    dict(relationship)

    返回关系中所有属性的字典。

    walk(relationship)

    执行walk()此关系的一个,依次产生其开始节点,关系本身和其结束节点。

    type(relationship)

    返回此关系的类型。

    Node和Relationship都扩展了PropertyDict类,它本身扩展了Python的内置字典。这意味着节点和关系都是可以包含按键索引的属性值的映射类型。

    与Neo4j本身一样,属性值可能不是None。缺少属性(即没有键)是建模缺少值的惯用方法。

    下面将更详细地描述PropertyDict类。

    class py2neo.data.PropertyDict(iterable, **kwargs)

    properties == other

    从中删除所有值后,返回Trueif properties等于。otherNoneother

    properties != other

    从中删除所有值后,返回Trueif properties是否等于。otherNoneother

    properties[key]

    使用键key或缺少键返回属性值。None

    properties[key] = value

    的值设置属性与键键到值或者删除属性值是None。

    setdefault(key,默认= None)

    如果key在PropertyDict中,则返回其值。如果不是,请插入具有default值的key并返回default,除非default为,在这种情况下什么也不做。值缺省默认。NoneNone

    update(可迭代= 无,** kwargs)

    使用来自iterable的键-值对以及后面来自kwargs的关键字参数更新PropertyDict 。个别属性已经在PropertyDict将覆盖那些在迭代,并随后被那些kwargs如果密钥匹配。如果存在任何值,None则将使用该键有效删除该属性。

    1.2 Subgraph objects

    子图是节点和关系的任意集合。根据定义,子图必须至少包含一个节点;零子图应该用None表示。要测试空值,可以使用内置的bool()函数。

    构造子图的最简单方法是使用标准集操作组合节点和关系。例如:

    >>> s = ab | ac
    
    >>> s
    
    {(alice:Person {name:"Alice"}),
    
     (bob:Person {name:"Bob"}),
    
     (carol:Person {name:"Carol"}),
    
     (Alice)-[:KNOWS]->(Bob),
    
     (Alice)-[:WORKS_WITH]->(Carol)}
    
    >>> s.nodes()
    
    frozenset({(alice:Person {name:"Alice"}),
    
               (bob:Person {name:"Bob"}),
    
               (carol:Person {name:"Carol"})})
    
    >>> s.relationships()
    
    frozenset({(Alice)-[:KNOWS]->(Bob),
    
               (Alice)-[:WORKS_WITH]->(Carol)})
    
    

    class py2neo.data.Subgraph(nodes, relationships)

    子图是一组不可变的节点和关系,可以作为许多图数据库函数的参数提供。它也是Node、Relationship和Walkable的基类,允许使用set操作组合这些类的实例。

    subgraph | other | ...

    并集。返回包含从所有节点和关系的新的子子,以及所有那些来自其他。两者共同的任何实体将仅被包含一次。

    subgraph & other & ...

    交集。返回一个新的子图,其中包含该子图和other共有的所有节点和关系。

    subgraph - other - ...

    Difference。返回一个包含存在于所有节点和关系的新的子子,但在不存在其他的,还有的是通过关系,连接所有节点子无论他们是否存在与否等。

    subgraph ^ other ^ ...

    对称差异。返回一个新的子图,该子图包含存在于子图或其他图中但不存在于两者中的所有节点和关系,以及通过这些关系连接的所有节点,无论它们是否为子图和other所共有。

    subgraph.keys()

    返回该子图中节点和关系使用的所有属性键的集合。

    subgraph.labels

    返回此子图中所有节点标签的集合。

    subgraph.nodes

    返回此子图中所有节点的集合。

    subgraph.relationships

    返回此子图中所有关系的集合。

    subgraph.types()

    返回此子图中所有关系类型的集合。

     

    1.3 Path objects and other Walkable types

    一个Walkable是一个添加了遍历信息的子图。构造Walkable的最简单的方法是连接其他图对象:

    >>> w = ab + Relationship(b, "LIKES", c) + ac
    
    >>> w
    
    (Alice)-[:KNOWS]->(Bob)-[:LIKES]->(Carol)<-[:WORKS_WITH]-(Alice)

    walkable对象的遍历是通过walk()函数实现的,该函数生成交替的节点和关系,始终以节点开始和结束。可以从任何方向遍历任何节点或关系一次或多次。

    class py2neo.data.Walkable(iterable)

    walkable + other + ...

    连接。返回一个新的Walkable,表示Walkable的walk()和other的walk()。只有当walkable的结束节点与other的开始节点或结束节点相同时才有可能这样做;在后一种情况下,other将被反向遍历。

    从一个操作数重叠到另一个操作数的节点在返回的可行走性中不会重复。

    walk(walkable)

    执行一个walkable的walk(),产生交替的节点和关系。

    start_node

    返回在walk()此对象的上遇到的第一个节点。

    end_node

    返回walk()此对象上遇到的最后一个节点。

    nodes

    返回此walkable的walk()遍历的所有节点的元组,按第一次遇到节点的顺序列出。

    relationships

    返回此walkable的walk()遍历的所有关系的元组,并按第一次遇到的顺序列出。

    class py2neo.data.Path(*entities)

    路径是由一些Cypher查询返回的walkable类型。

    py2neo.data.walk(*walkables)

    按顺序遍历提供的参数,产生交替的节点和关系。

    1.4 Record objects

    class py2neo.data.Record(iterable=())

    Record对象保存有序的键值集合。它在许多方面与namedtuple相似,但只允许通过括号语法访问字段,并提供更多功能。Record扩展了元组和映射。

    record[index]

     

    record[key]

    返回具有指定键或索引的记录的值。

    len(record)

    返回记录中的字段数。

    dict(record)

    返回记录的dict表示。

    data(*keys)

    以字典的形式返回此记录的键和值,可选地仅按索引或键包含某些值。如果键不存在于记录内,则会包括但值为None的键;超出范围的索引将触发一个IndexError。

    Parameters: keys –要包括的项目的索引或键;如果没有提供,则将包括所有值

    Returns:值的字典,按字段名称键入

    Raises:如果指定了越界索引,则使用IndexError

    get(key, default=None)

    按索引或键从记录中获取单个值。如果指定的项不存在,则返回默认值。

    Parameters:key – index or key

    default –如果键不存在,则返回默认值

    Returns:选定值

    index(key)

    返回给定项的索引。

    items(*keys)

    以键元组和值元组的列表的形式返回记录的字段

    Parameters:keys – 要包括的项目的索引或键;如果没有提供,则将包括所有值

    Returns:list of (key, value) tuples

    keys()

    返回记录的键。

    Returns:list of key names

    to_subgraph()

    返回包含此记录中所有图结构的联合的子图。

    Returns:Subgraph object

    values(*keys)

    返回记录的值,根据索引或键可选择筛选仅包含某些值。

    Parameters:keys – 要包括的项目的索引或键;如果没有提供,则将包括所有值

    Returns:list of values

    1.5 Table objects

    class py2neo.data.Table(records, keys=None)

    表保存记录对象列表,这些对象通常是作为Cypher查询的结果接收的。它提供了一个方便的容器来处理整个结果,并提供了转换成各种输出格式的方法。表扩展列表。

    repr(table)

    返回包含此表的ASCII艺术作品表示形式的字符串。在内部,此方法write()使用header = True调用,将输出写入io.StringIO实例。

    _repr_html_()

    返回包含此表的HTML表示形式的字符串。Jupyter笔记本使用此方法在浏览器中本地显示表。在内部,此方法write_html()使用header = True调用,将输出写入io.StringIO实例。

    keys()

    返回此表的字段名称列表。

    field(键)[资源]

    返回给定字段的元数据字典。元数据包含以下值:

    Type:表示字段值的单个类或元组。

    Numeric:如果所有字段值都是数值类型,则为True,否则为False。

    Optional:如果任何字段值为None,则为True,否则为False。

     

    • write(file=None, header=None, skip=None, limit=None, auto_align=True, padding=1, separator='|', newline='\r\n')

    Write data to a human-readable ASCII art table.

    Parameters

    • file – 能够接收输出的类文件对象
    • header – 用于添加列标题的布尔标志
    • skip – 开始输出之前要跳过的记录数
    • limit – 输出中包含的最大记录数
    • auto_align – 如果为真,则右对齐数值
    • padding – 列分隔符和值之间要包含的空格数
    • separator – 列分隔符
    • newline – 换行字符序列

    Returns

    the number of records included in output

    • write_html(file=None, header=None, skip=None, limit=None, auto_align=True)

    Write data to an HTML table

    Parameters

    • file – 能够接收输出的类文件对象
    • header –用于添加列标题的布尔标志
    • skip – 开始输出之前要跳过的记录数
    • limit – 输出中包含的最大记录数
    • auto_align –如果为真,则右对齐数值

    Returns

    the number of records included in output

    • write_separated_values(separator, file=None, header=None, skip=None, limit=None, newline='\r\n', quote='"')

    将数据写入分隔符分隔的文件。

    Parameters

    • separator – 字段分隔字符
    • file – 能够接收输出的类文件对象
    • header – 布尔标志(或click.secho字典样式)用于添加列标题
    • skip – 开始输出之前要跳过的记录数
    • limit – 输出中包含的最大记录数
    • newline – 换行字符序列
    • quote – 引用字符

    Returns  输出中包含的记录数

    • write_csv(file=None, header=None, skip=None, limit=None)

    以兼容rfc4180的逗号分隔值写入数据。这是对write_separated_values()的定制调用。

    • write_tsv(file=None, header=None, skip=None, limit=None)

    以制表符分隔的值写入数据。这是对write_separated_values()的定制调用。

    展开全文
  • py2neo-3.1.1-py2.py3-none-any.whl 使用方式 pip install py2neo-3.1.1-py2.py3-none-any.whl 安装
  • from py2neo import Graph 链接数据库: graph = Graph('http://localhost:7474', username='neo4j', password='密码') 2.搜索 2.1普通搜索全部节点并输出信息(string格式) nodes=[] dict_node = {} ...

    1.搜索前
    导入架包:

    import pymysql
    from py2neo import Graph
    

    链接数据库:

    graph = Graph('http://localhost:7474', username='neo4j', password='密码')
    

    2.搜索#company即为要查询的数据库中的label
    2.1普通搜索全部节点并输出信息(string格式)

    nodes=[]
    dict_node = {}
    nodes_data_all = self.graph.run("MATCH (n) RETURN n").data()#取出所有节点
              	for node in  nodes_data_all:
               	 	name = node['n']['name']
                 	href = node['n']['href']
                 	content= node['n']['content']
                 	#node的第一个参数['n']对应查询中的RETURN n;第二个参数对应的是数据库中每个节点的一个属性
    				dict_node['name'] = name
                    dict_node['href'] = href
                    dict_node['content'] = content
                    self.nodes.append(dict_node)
                    #将所有节点赋值给dict_node字典
                    #将每个dict_node追加都nodes列表中
    

    2.2 搜索某个节点的所有相邻节点

    #通过名字搜索,假设数据库中有
    str=“某个名字”
    find_rela = graph.run("match data=(a:company{name:'%s'})-[re]->(n:apple_drug) return n"%str).data()#如果return的是re的话则输出关系(即相当于三元组)
            for node in find_rela:
                print(node['n']['name'])
    

    2.3搜索某一个节点:

     str1=“某个名字”
     find_self= graph.run("match (n:company{name:'%s'}) return n"%str1).data()
      for node1 in find_self:
      print(node1['n']['name']
    
    展开全文
  • cytoscape_py2neo 用于学习如何从 py2neo 获取 neo4j 图形数据并使用 cytoscape.js 显示图形
  • Is there a way to change a relationship property once it has been set using py2neo or cypher? I'm creating an inventory tracker and once an item is "CHECKED_OUT" a property called "status" in the rela...

    Is there a way to change a relationship property once it has been set using py2neo or cypher? I'm creating an inventory tracker and once an item is "CHECKED_OUT" a property called "status" in the relationship is set to "True". Ideally, once the item is returned or checked in, I'd like to change the "status" property to "False". This way I can keep track of the item and prevent it from being checked out twice.

    Here is my code for creating the relationship for a checkout transaction:

    def check_out(self, barcode):

    emp = self

    item = barcode

    id = str(uuid.uuid4())

    timestamp = int(datetime.now().strftime("%s"))

    date = datetime.now().strftime("%F")

    status=True

    rel = Relationship(emp, "CHECKED_OUT", item, id=id, timestamp=timestamp, date=date, status=status)

    if not(graph.create_unique(rel)):

    return True

    else:

    return False

    I've read through the py2neo API and I can't seem to find the answer. If modifying the relationship is the wrong approach, can you offer a better one?

    解决方案

    Something along this line should work:

    def check_in(self, barcode):

    item = barcode

    # get the relationship

    for rel in graph.match(start_node=self, rel_type="CHECKED_OUT", end_node=item):

    # set property

    rel.properties["status"] = False

    rel.push()

    展开全文
  • py2neo.database – Graph Databases The py2neo.database package contains classes and functions required to interact with a Neo4j server. For convenience, many of these classes are also exposed through...

    py2neo.database – Graph Databases

    The py2neo.database package contains classes and functions required to interact with a Neo4j server. For convenience, many of these classes are also exposed through the top-level package, py2neo.

    The most useful of the classes provided here is the Graph class which represents a Neo4j graph database instance and provides access to a large portion of the most commonly used py2neo API.

    To run a query against a local database is straightforward:

     >>> from py2neo import Graph
     >>> graph = Graph(password="password")
     >>> graph.run("UNWIND range(1, 3) AS n RETURN n, n * n as n_sq").to_table()
        n | n_sq
     -----|------
        1 |    1
        2 |    4
        3 |    9

    Getting connected

    The GraphService, Graph, and SystemGraph classes all accept an argument called profile plus individual keyword settings. Internally, these arguments are used to construct a ConnectionProfile object which holds these details.

    The profile can either be a URI or a base ConnectionProfile object. The settings are individual overrides for the values within that, such as host or password. This override mechanism allows several ways of specifying the same information. For example, the three variants below are all equivalent:

     >>> from py2neo import Graph
     >>> graph_1 = Graph()
     >>> graph_2 = Graph(host="localhost")
     >>> graph_3 = Graph("bolt://localhost:7687")

    Omitting the profile argument completely falls back to using the default ConnectionProfile. More on this, and other useful information, can be found in the documentation for that class.

    URIs

    The general format of a URI is <scheme>://[<user>[:<password>]@]<host>[:<port>]. Supported URI schemes are:

    • bolt - Bolt (unsecured)

    • bolt+s - Bolt (secured with full certificate checks)

    • bolt+ssc - Bolt (secured with no certificate checks)

    • http - HTTP (unsecured)

    • https - HTTP (secured with full certificate checks)

    • http+s - HTTP (secured with full certificate checks)

    • http+ssc - HTTP (secured with no certificate checks)

    Note that py2neo does not support routing with a Neo4j causal cluster, so neo4j://... URIs are not available. For this functionality, please use the official Neo4j Driver for Python.

    Individual settings

    The full set of supported settings are:

    KeywordDescriptionTypeDefault
    schemeUse a specific URI schemestr'bolt'
    secureUse a secure connection (TLS)boolFalse
    verifyVerify the server certificate (if secure)boolTrue
    hostDatabase server host namestr'localhost'
    portDatabase server portint7687
    addressColon-separated host and port stringstr'localhost:7687'
    userUser to authenticate asstr'neo4j'
    passwordPassword to use for authenticationstr'password'
    authA 2-tuple of (user, password)tuple('neo4j', 'password')

    GraphService objects

    • class py2neo.database.``GraphService(profile=None, **settings)[source]

      The GraphService class is the top-level accessor for an entire Neo4j graph database management system (DBMS). Within the py2neo object hierarchy, a GraphService contains one or more Graph objects in which data storage and retrieval activity chiefly occurs.An explicit URI can be passed to the constructor:>>> from py2neo import GraphService >>> gs = GraphService("bolt://camelot.example.com:7687")Alternatively, the default value of bolt://localhost:7687 is used:>>> default_gs = GraphService() >>> default_gs <GraphService uri='bolt://localhost:7687'>Note Some attributes of this class available in earlier versions of py2neo are no longer available, specifically kernel_start_time, primitive_counts, store_creation_time, store_file_sizes and store_id, along with the query_jmx method. This is due to a change in Neo4j 4.0 relating to how certain system metadata is exposed. Replacement functionality may be reintroduced in a future py2neo release.Changed in 2020.0: this class was formerly known as ‘Database’, but was renamed to avoid confusion with the concept of the same name introduced with the multi-database feature of Neo4j 4.0.iter(graph_service)Yield all named graphs.For Neo4j 4.0 and above, this yields the names returned by a SHOW DATABASES query. For earlier versions, this yields no entries, since the one and only graph in these versions is not named.New in version 2020.0.graph_service[name]Access a Graph by name.New in version 2020.0.**property configA dictionary of the configuration parameters used to configure Neo4j.>>> gs.config['dbms.connectors.default_advertised_address'] 'localhost'property connectorThe Connector providing communication for this graph service.New in version 2020.0.**property default_graphThe default Graph exposed by this graph service.classmethod forget_all()[source]Forget all cached GraphService details.property kernel_versionThe Version of Neo4j running.keys()[source]Return a list of all Graph names exposed by this graph service.New in version 2020.0.**property productThe product name.property profileThe ConnectionProfile for which this graph service is configured. This attribute is simply a shortcut for connector.profile.New in version 2020.0.**property system_graphThe SystemGraph exposed by this graph service.New in version 2020.0.**property uriThe URI to which this graph service is connected. This attribute is simply a shortcut for connector.profile.uri.

    Graph objects

    • class py2neo.database.``Graph(profile=None, name=None, **settings)[source]

      The Graph class provides a handle to an individual named graph database exposed by a Neo4j graph database service.Connection details are provided using either a URI or a ConnectionProfile, plus individual settings, if required.The name argument allows selection of a graph database by name. When working with Neo4j 4.0 and above, this can be any name defined in the system catalogue, a full list of which can be obtained through the Cypher SHOW DATABASES command. Passing None here will select the default database, as defined on the server. For earlier versions of Neo4j, the name must be set to None.>>> from py2neo import Graph >>> sales = Graph("bolt+s://g.example.com:7687", name="sales") >>> sales.run("MATCH (c:Customer) RETURN c.name") c.name --------------- John Smith Amy Pond Rory WilliamsThe system graph, which is available in all 4.x+ product editions, can also be accessed via the SystemGraph class.>>> from py2neo import SystemGraph >>> sg = SystemGraph("bolt+s://g.example.com:7687") >>> sg.call("dbms.security.listUsers") username | roles | flags ----------|-------|------- neo4j | null | []In addition to the core connection details that can be passed to the constructor, the Graph class can accept several other settings:KeywordDescriptionTypeDefaultuser_agentUser agent to send for all connectionsstr(depends on URI scheme)max_connectionsThe maximum number of simultaneous connections permittedint40Once obtained, the Graph instance provides direct or indirect access to most of the functionality available within py2neo.auto()[source]Create a new auto-commit Transaction.New in version 2020.0.begin(autocommit=False)[source]Begin a new Transaction.Parametersautocommit – (deprecated) if True, the transaction will automatically commit after the first operationChanged in version 2020.0: the ‘autocommit’ argument is now deprecated. Use the ‘auto’ method instead.**property callAccessor for listing and calling procedures.This property contains a ProcedureLibrary object tied to this graph, which provides links to Cypher procedures in the underlying implementation.Calling a procedure requires only the regular Python function call syntax:>>> g = Graph() >>> g.call.dbms.components() name | versions | edition --------------|------------|----------- Neo4j Kernel | ['3.5.12'] | communityThe object returned from the call is a Cursor object, identical to that obtained from running a normal Cypher query, and can therefore be consumed in a similar way.Procedure names can alternatively be supplied as a string:>>> g.call["dbms.components"]() name | versions | edition --------------|------------|----------- Neo4j Kernel | ['3.5.12'] | communityUsing dir() or iter() on the call attribute will yield a list of available procedure names.New in version 2020.0.create(subgraph)[source]Run a create() operation within a Transaction.Parameterssubgraph – a Node, Relationship or other Subgraphdelete(subgraph)[source]Run a delete() operation within an autocommit Transaction. To delete only the relationships, use the separate() method.Note that only entities which are bound to corresponding remote entities though the graph and identity attributes will trigger a deletion.Parameterssubgraph – a Node, Relationship or other Subgraph objectdelete_all()[source]Delete all nodes and relationships from this Graph.Warning This method will permanently remove all nodes and relationships from the graph and cannot be undone.evaluate(cypher, parameters=None, kwparameters)[source]Run a evaluate() operation within an autocommit Transaction.Parameterscypher* – Cypher statementparameters – dictionary of parametersReturnsfirst value from the first record returned or None.exists(subgraph)[source]Run a exists() operation within an autocommit Transaction.Parameterssubgraph – a Node, Relationship or other Subgraph objectReturnsmatch(nodes=None*, r_type=None, limit=None)[source]Match and return all relationships with specific criteria.For example, to find all of Alice’s friends:for rel in graph.match((alice, ), r_type="FRIEND"): print(rel.end_node["name"])Parametersnodes – Sequence or Set of start and end nodes (None means any node); a Set implies a match in any directionr_type – type of relationships to match (None means any type)limit – maximum number of relationships to match (None means unlimited)match_one(nodes=None, r_type=None)[source]Match and return one relationship with specific criteria.Parametersnodes – Sequence or Set of start and end nodes (None means any node); a Set implies a match in any directionr_type – type of relationships to match (None means any type)merge(subgraph, label=None, property_keys*)[source]Run a merge() operation within an autocommit Transaction.The example code below shows a simple merge for a new relationship between two new nodes:>>> from py2neo import Graph, Node, Relationship >>> g = Graph() >>> a = Node("Person", name="Alice", age=33) >>> b = Node("Person", name="Bob", age=44) >>> KNOWS = Relationship.type("KNOWS") >>> g.merge(KNOWS(a, b), "Person", "name")Following on, we then create a third node (of a different type) to which both the original nodes connect:>>> c = Node("Company", name="ACME") >>> c.__primarylabel__ = "Company" >>> c.__primarykey__ = "name" >>> WORKS_FOR = Relationship.type("WORKS_FOR") >>> g.merge(WORKS_FOR(a, c) | WORKS_FOR(b, c))For details of how the merge algorithm works, see the merge() method. Note that this is different to a Cypher MERGE.Parameterssubgraph* – a Node, Relationship or other Subgraph objectlabel – label on which to match any existing nodesproperty_keys – property keys on which to match any existing nodesproperty* nameThe name of this graph.New in version 2020.0.**property nodesA NodeMatcher for this graph.This can be used to find nodes that match given criteria:>>> graph = Graph() >>> graph.nodes[1234] (_1234:Person {name: 'Alice'}) >>> graph.nodes.get(1234) (_1234:Person {name: 'Alice'}) >>> graph.nodes.match("Person", name="Alice").first() (_1234:Person {name: 'Alice'})Nodes can also be efficiently counted using this attribute:>>> len(graph.nodes) 55691 >>> len(graph.nodes.match("Person", age=33)) 12 ``play(work, args=None, kwargs=None)[source]Call a function representing a transactional unit of work.The function must always accept a Transaction object as its first argument. Additional arguments can be passed though the args and kwargs arguments of this method.Parameterswork – function containing the unit of workargs – sequence of additional positional arguments to pass into the functionkwargs – mapping of additional keyword arguments to pass into the functionNew in version 2020.0.pull(subgraph)[source]Pull data to one or more entities from their remote counterparts.Parameterssubgraph – the collection of nodes and relationships to pullpush(subgraph)[source]Push data from one or more entities to their remote counterparts.Parameterssubgraph – the collection of nodes and relationships to pushproperty relationshipsA RelationshipMatcher for this graph.This can be used to find relationships that match given criteria as well as efficiently count relationships.run(cypher, parameters=None, kwparameters)[source]Run a run() operation within an autocommit Transaction.Parameterscypher** – Cypher statement**parameters** – dictionary of parameters**kwparameters** – extra keyword parametersReturns`schema` = NoneThe Schema resource for this Graph.separate(subgraph)[source]Run a separate() operation within an autocommit Transaction.Note that only relationships which are bound to corresponding remote relationships though the graph and identity attributes will trigger a deletion.Parameterssubgraph – a Node, Relationship or other Subgraphservice = NoneThe GraphService to which this Graph belongs.

    SystemGraph objects

    • class py2neo.database.``SystemGraph(profile=None, **settings)[source]

      A subclass of Graph that provides access to the system database for the remote DBMS. This is only available in Neo4j 4.0 and above.New in version 2020.0.

    Schema objects

    • class py2neo.database.``Schema(graph)[source]

      The schema resource attached to a Graph instance.create_index(label, property_keys)[source]Create a schema index for a label and property key combination.create_uniqueness_constraint(label*, property_key)[source]Create a node uniqueness constraint for a given label and property key.While indexes support the use of composite keys, unique constraints may only be tied to a single property key.drop_index(label, property_keys)[source]Remove label index for a given property key.drop_uniqueness_constraint(label*, property_key)[source]Remove the node uniqueness constraint for a given label and property key.get_indexes(label)[source]Fetch a list of indexed property keys for a label.get_uniqueness_constraints(label)[source]Fetch a list of unique constraints for a label. Each constraint is the name of a single property key.property node_labelsThe set of node labels currently defined within the graph.property relationship_typesThe set of relationship types currently defined within the graph.

    ProcedureLibrary objects

    • class py2neo.database.``ProcedureLibrary(graph)[source]

      Accessor for listing and calling procedures.This object is typically constructed and accessed via the Graph.call() attribute. See the documentation for that attribute for usage information.New in version 2020.0.

    Procedure objects

    • class py2neo.database.``Procedure(graph, name)[source]

      Represents an individual procedure.New in version 2020.0.

    展开全文
  • 用python使用py2neo时候报“ModuleNotFoundError:No module named 'py2neo'”的错误。 1 首先cmd里面输入“py2neo version”,会显示“4.2.0” OK,说明我的py2neo装了。 2 cmd里输入“python --version” 会...
  • py2neo interface

    2015-12-24 00:31:22
    该代码使用py2neo实现了用python对neo4j的操作,提供节点信息的输入以及据此创建节点部分,建立连接时须把neo4j密码改为自己所设密码
  • py2neo database.pdf

    2021-08-10 16:39:48
    py2neo database.pdf
  • Py2neo的基本用法

    千次阅读 多人点赞 2019-09-05 14:49:45
    neo4j目前是图数据库的主流,neo4j的Cypher语法简单直观,但是不便于...另一个问题是py2neo文档的示例较少,而且不同版本的py2neo挺不相同,容易弄混。这里要讲的是目前的v4版本。 连接数据库和图 from py2neo impo...
  • python使用py2neo操作neo4j

    万次阅读 2019-10-24 14:00:24
    pip install py2neo 安装过程中,可能会报错: ERROR: ipython 5.1.0 has requirement prompt-toolkit<2.0.0,>=1.0.3, but you'll have prompt-toolkit 2.0.10 which is incompatible. 意思是 Ipython需要...
  • 2.py2neo版本4.1 3.python版本python3.4 问题 pip install py2neo==4.1 安装失败,提示: Cannot uninstall 'urllib3'. It is a distutils installed project and thus we cannot accurately deter...
  • py2neo学习

    2021-06-15 17:01:00
    py2neo学习 这篇文章是我在使用python操作neo4j时总结的参考文档,主要的参考文献是py2neo的手册 GraphService GraphService 包含一个或多个Graph主要发生数据存储和检索活动的对象。 from py2neo import ...
  • py2neo安装

    千次阅读 2019-03-10 15:34:00
    py2neo安装 pip install py2neo==3.1.2 用py2neo 就用这个版本,否则新版会让你崩溃 posted on 2019-03-10 15:34 luoganttcc 阅读(...)...
  • py2neo使用

    2018-12-05 11:25:25
    python3使用neo4j:py2neo v4 https://py2neo.org/v4/ https://github.com/technige/py2neo 安装pip3 install py2neo 简单使用: &gt;&gt;&gt; from py2neo import * &gt;&gt;&gt; ...
  • 输入 `g.run('CALL db.relationshipTypes()') ...py2neo.database.Cursor object at 0x00000227963E6CC8>` 将 py2neo.database.Cursor object转为其他格式输入 g.run('CALL db.relationshipTypes()').to_series()
  • py2neo操作neo4j

    2020-07-20 18:35:52
    docker run -it -d -p 7474:7474 -p 7687:7687 neo4j:3.4 ...neo4j/neo4j # -*- coding: utf-8 -*- # @Author: xiaodong # @Date : 2020/7/20 import json ...from py2neo import Graph, Node, Relationship
  • 主要介绍了Python使用py2neo操作图数据库neo4j的方法,结合实例形式详细分析了Python使用py2neo操作图数据库neo4j的具体步骤、原理、相关使用技巧与操作注意事项,需要的朋友可以参考下
  • py2neo 使用手册

    2021-03-22 16:37:51
    from py2neo import Graph class Neo4jConnection: """Neo4j 连接类""" def __init__(self, host, user, password, port): self.graph = Graph(host=host, user=user, password=password, por
  • 安装py2neo

    千次阅读 2018-01-06 16:14:31
    从网上下载py2neo-3.1.1.zip解压 然后cmd cd 进入py2neo-3.1.1文件夹,输入 python setup.py install 即可安装 引用:...
  • py2neo-release-1.6.3.tar.gz

    2021-04-08 18:25:42
    泪崩,最新的镜像都删除了,好不容易找到了老版py2neo,供大家学习分享。仅供学习使用,侵权联系我删除
  • py2neo-release-1.6.2.tar.gz

    2021-04-08 18:24:56
    泪崩,最新的镜像都删除了,好不容易找到了老版py2neo,供大家学习分享。仅供学习使用,侵权联系我删除

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,105
精华内容 1,242
关键字:

py2neo