semvec/pypi-packages huggingface dataset:
pygraphdb 2.0.3
A connect graphdb package
License: Apache
Requires Python: >=3.6

# graphdb

#### 介绍
    python 连接 graphdb 数据库的包

#### 功能
    一、数据管理
        1. 通过执行SPARQL语句就可查询和更新Graph数据库
        2. 下载数据并保存
        3. 上传数据
        4. 删除所有的节点数据
    
    二、数据库管理
        1. 获取现有的repository列表
        2. 删除现有的repository
        3. 创建一个repository
        4. 重启现有的repository
        5. 获取现有的repository size


#### 安装教程
    pip install pygraphdb


#### 快速上手

    
    1. 导入包
    
    import pygraphdb
    
    2. 数据库 config
    
    host = '0.0.0.0'
    port = '7200'
    db_name = 'db_name'
    user = 'admin'
    password = 'password'
    
    3. sparql 语句(例)
    
    sparql = "PREFIX disease_type_iri:<http://schema.omaha.org.cn/property/> " \
         "select distinct ?x ?y where { ?x disease_type_iri:Alternatename ?y .}"
         
    4. 连接数据库
    
    db = pygraphdb.connect(host=host, port=port, user=user, password=password, db=db_name)
    
    5. 获取 cursor
    
    cur = db.cursor()
    
    6. 执行sparql语句，得到结果
    
    result = cur.execute(sparql)
    
    7. 打印结果
    
    print(result)
    
    8. 关闭 cursor
    
    cur.close()
    
    9. 关闭数据库
    
    db.close()

#### 使用with连接

    1.第一种方式
    
    with pygraph.connect(host, port, user, password, db) as db2:
        #获取 cursor
        cur2 = db2.cursor()
        #执行sparql语句，得到结果
        result2 = cur2.execute(sparql)
        cur2.close()
        print(result2)
    
    2.第二种方式
    
    db3 = pygraph.connect(host, port, db, user, password, db)
    with db3.cursor() as cur3:
        result3 = cur3.execute(sparql)
        print(result3)
    db3.close()

#### 数据管理
    import pygraphdb

    host = '0.0.0.0'
    port = '7200'
    db_name = 'db_name'
    user = 'admin'
    password = 'password'

    db = pygraphdb.connect(host, port, user, password, db_name)

    cur = db.cursor()

    """
    执行查询语句
    """
    r = cur.execute('select * where {?s ?p ?o .} limit 100 ')
    print(r)


    """
    上传数据
    """
    r2 = cur.upload_data('./example.owl')
    print(r2)


    """
    下载数据
    """
    r3 = cur.download_data('./download_result.owl')
    print(r3)


    """
    删除全部节点数据
    """
    r4 = cur.delete_all_data()
    print(r4)

    cur.close()

    db.close()

#### 数据库管理
    import pygraphdb

    host = '0.0.0.0'
    port = '7200'
    user = 'admin'
    password = 'password'

    db = pygraphdb.connect(host, port, user, password)

    manager = db.manage_repository()
    
    """
    创建一个repository
    """
    db_name = 'example'
    r = manager.create_repository_graphdb_free(db_name)
    print(r)
    
    """
    删除一个repository
    """
    r2 = manager.delete_repository(db_name)
    print(r2)
    
    
    """
    查询所有的repository列表
    """
    r3 = manager.get_repository_list()
    print(r3)
    
    
    """
    重启repository
    """
    r4 = manager.restart_repository(db_name)
    print(r4)
    
    
    """
    获取数据库大小
    """
    r5 = manager.get_repository_size(db_name)
    print(r5)

    manager.close()

    db.close()



#### 参与贡献
    刘洪波



#### 参考资料

grapddb 使用教程： 
https://graphdb.ontotext.com/documentation/free/index.html