arangodb的python驱动程序
python-arango的Python项目详细描述
欢迎来到github页面,python arango,这是一个用于ArangoDB的python驱动程序。
功能
- pythonic接口
- 重量轻
- 高API覆盖率
兼容性
- 支持Python版本2.7、3.4、3.5、3.6和3.7
- python arango 5.x支持arangodb 3.5+
- python arango 4.x仅支持arangodb 3.3~3.4
- python arango 3.x仅支持arangoDB 3.0~3.2
- python arango 2.x仅支持arangodb 1.x~2.x
安装
从PyPi安装稳定版本:
~$ pip install python-arango
直接从GitHub安装最新版本:
~$ pip install -e git+git@github.com:joowani/python-arango.git@master#egg=python-arango
根据环境的不同,您可能需要使用sudo。
开始
下面是一个简单的用法示例:
fromarangoimportArangoClient# Initialize the client for ArangoDB.client=ArangoClient(hosts='http://localhost:8529')# Connect to "_system" database as root user.sys_db=client.db('_system',username='root',password='passwd')# Create a new database named "test".sys_db.create_database('test')# Connect to "test" database as root user.db=client.db('test',username='root',password='passwd')# Create a new collection named "students".students=db.create_collection('students')# Add a hash index to the collection.students.add_hash_index(fields=['name'],unique=True)# Insert new documents into the collection.students.insert({'name':'jane','age':39})students.insert({'name':'josh','age':18})students.insert({'name':'judy','age':21})# Execute an AQL query and iterate through the result cursor.cursor=db.aql.execute('FOR doc IN students RETURN doc')student_names=[document['name']fordocumentincursor]
下面是另一个图形示例:
fromarangoimportArangoClient# Initialize the client for ArangoDB.client=ArangoClient(hosts='http://localhost:8529')# Connect to "test" database as root user.db=client.db('test',username='root',password='passwd')# Create a new graph named "school".graph=db.create_graph('school')# Create vertex collections for the graph.students=graph.create_vertex_collection('students')lectures=graph.create_vertex_collection('lectures')# Create an edge definition (relation) for the graph.register=graph.create_edge_definition(edge_collection='register',from_vertex_collections=['students'],to_vertex_collections=['lectures'])# Insert vertex documents into "students" (from) vertex collection.students.insert({'_key':'01','full_name':'Anna Smith'})students.insert({'_key':'02','full_name':'Jake Clark'})students.insert({'_key':'03','full_name':'Lisa Jones'})# Insert vertex documents into "lectures" (to) vertex collection.lectures.insert({'_key':'MAT101','title':'Calculus'})lectures.insert({'_key':'STA101','title':'Statistics'})lectures.insert({'_key':'CSC101','title':'Algorithms'})# Insert edge documents into "register" edge collection.register.insert({'_from':'students/01','_to':'lectures/MAT101'})register.insert({'_from':'students/01','_to':'lectures/STA101'})register.insert({'_from':'students/01','_to':'lectures/CSC101'})register.insert({'_from':'students/02','_to':'lectures/MAT101'})register.insert({'_from':'students/02','_to':'lectures/STA101'})register.insert({'_from':'students/03','_to':'lectures/CSC101'})# Traverse the graph in outbound direction, breadth-first.result=graph.traverse(start_vertex='students/01',direction='outbound',strategy='breadthfirst')
查看documentation了解更多信息。
贡献
请在提交拉取请求之前查看此page。谢谢!