Package: terminusdb-client
Python client for TerminusDB and TerminusCMS.TerminusDBis anopen-sourcegraph database
and document store. It allows you to link JSON documents in a powerful knowledge
graph all through a simple document API.TerminusCMSis a hosted headless content management system. It is built upon TerminusDB and is a developer-focused data management platform for complex data and content infrastructure.Sign up and clone a demo project to see how it works.RequirementsTerminusDB v10.0Python >=3.7Release Notes and Previous VersionsTerminusDB Client v10.0 works with TerminusDB v10.0 and TerminusCMS. Please check theRelease Notesto find out what has changed.InstallationTerminusDB Client can be downloaded from PyPI using pip:python -m pip install terminusdb-clientThis only includes the core Python Client (Client) and WOQLQuery.If you want to use woqlDataframe or the import and export CSV function in the Scaffolding CLI tool:python -m pip install terminusdb-client[dataframe]if you are installing fromzshyou have to quote the argument like this:python -m pip install 'terminusdb-client[dataframe]'Install from source:python -m pip install git+https://github.com/terminusdb/terminusdb-client-python.gitDemoUsagePython clientConnect to a serverConnect to local hostfromterminusdb_clientimportClientclient=Client("http://127.0.0.1:6363/")client.connect()Connect to TerminusCMScheck the documentation for TerminusCMS about how to add theAPI tokento the environment variablefromterminusdb_clientimportClientteam="MyTeam"client=Client(f"https://dashboard.terminusdb.com/{team}/")client.connect(team="MyTeam",use_token=True)Create a databaseclient.create_database("MyDatabase")Create a schemafromterminusdb_client.schemaimportSchema,DocumentTemplate,RandomKeymy_schema=Schema()classPet(DocumentTemplate):_schema=my_schemaname:strspecies:strage:intweight:floatmy_schema.commit(client)Create and insert documentsmy_dog=Pet(name="Honda",species="Huskey",age=3,weight=21.1)my_cat=Pet(name="Tiger",species="Bengal cat",age=5,weight=4.5)client.insert_document([my_dog,my_cat])Get back all documentsprint(list(client.get_all_documents()))[{'@id': 'Pet/b5edacf854e34fe79c228a91e2af45fb', '@type': 'Pet', 'age': 5, 'name': 'Tiger', 'species': 'Bengal cat', 'weight': 4.5}, {'@id': 'Pet/cdbe3f6d49394b38b952ae315309256d', '@type': 'Pet', 'age': 3, 'name': 'Honda', 'species': 'Huskey', 'weight': 21.1}]Get a specific documentprint(list(client.query_document({"@type":"Pet","age":5})))[{'@id': 'Pet/145eb73966d14a1394f7cd5576d7d0b8', '@type': 'Pet', 'age': 5, 'name': 'Tiger', 'species': 'Bengal cat', 'weight': 4.5}]Delete a databaseclient.delete_database("MyDatabase")Scaffolding CLI toolStart a project in the directory$tdbpystartproject
Pleaseenteraprojectname(thiswillalsobethedatabasename):mydb
Pleaseenteranendpointlocation(pressentertouselocalhostdefault)[http://127.0.0.1:6363/]:
config.jsonandschema.pycreated,pleasecustomizethemtostartyourproject.Import a CSV namedgrades.csv$tdbpyimportcsvgrades.csv--na=error
0it[00:00,?it/s]SchemaobjectGradescreatedwithgrades.csvinsertedintodatabase.
schema.pyisupdatedwithmydbschema.
1it[00:00,1.00it/s]Recordsingrades.csvinsertedastypeGradesintodatabasewithLexicalids.Get documents with query$tdbpyalldocs--typeGrades-qgrade="B-"[{'@id':'Grades/Android_Electric_087-65-4321_42.0_23.0_36.0_45.0_47.0_B-','@type':'Grades','final':47.0,'first_name':'Electric','grade':'B-','last_name':'Android','ssn':'087-65-4321','test1':42.0,'test2':23.0,'test3':36.0,'test4':45.0},{'@id':'Grades/Elephant_Ima_456-71-9012_45.0_1.0_78.0_88.0_77.0_B-','@type':'Grades','final':77.0,'first_name':'Ima','grade':'B-','last_name':'Elephant','ssn':'456-71-9012','test1':45.0,'test2':1.0,'test3':78.0,'test4':88.0},{'@id':'Grades/Franklin_Benny_234-56-2890_50.0_1.0_90.0_80.0_90.0_B-','@type':'Grades','final':90.0,'first_name':'Benny','grade':'B-','last_name':'Franklin','ssn':'234-56-2890','test1':50.0,'test2':1.0,'test3':90.0,'test4':80.0}]Delete the database$tdbpydeletedb
Doyouwanttodelete'mydb'?WARNING:Thisoperationisnon-reversible.[y/N]:y
mydbdeleted.Please check thefull Documentationfor more information.Guides & TutorialsVisit our documentation for a range of short how-to guides,how-to use the Python Clientandhow to use the collaboration features with the Python Client. Alternatively, undertake theGetting Started with the Python Client Tutorial Series..TestingClone this repositorygit clone https://github.com/terminusdb/terminusdb-client-python.gitInstall all development dependencies using poetry$makeinit(a) To run test files only$poetryrunpytestterminusdb_client/tests(b) To run full test$poetryruntox-etestOr you can run tests inpoetry shellthen no need to usepoetry runDocumentationVisit ourTerminusDB Documentationfor the full explanation of using TerminusDB.Documentation specifically on the latest version of the Python Client can be foundhere.Generating Documentation Locally using SphinxClone this repositorygit clone https://github.com/terminusdb/terminusdb-client-python.gitInstall all development dependencies$makeinitChange the directory to docs$cddocs/Build with Sphinx$makehtmlThe output files are underdocs/build/html, openindex.htmlin your browser to inspect.Report IssuesIf you encounter any issues, pleasereport themwith your os and environment setup, the version that you are using and a simple reproducible case.If you have other questions, you can ask in our communitycommunity SubredditorDiscord server.CommunityCome visit us on ourdiscord serveror ourcommunity Subreddit. We are also onTwitterContributeIt will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add some test(s) of what value you adding.Please checkCONTRIBUTING.mdfor more information.LicenceApache License (Version 2.0)Copyright (c) 2019