Welcome to pyArango’s documentation!¶
pyArango is a python driver for the NoSQL amazing database ArangoDB first written by Tariq Daouda. As of January 2019 pyArango was handed over to the ArangoDB-Community that now ensures the developement and maintenance. It has a very light interface and built in validation. pyArango is distributed under the ApacheV2 Licence and the full source code can be found on github.
Key Features¶
pyArango is geared toward the developer. It’s here to help to you develop really cool apps using ArangoDB, really fast.
- Light and Simple interface
- Built-in Validation of fields on setting or on saving
- Support for all index types
- Supports graphs, traversals and all types of queries
- Caching of documents with Insertions and Lookups in O(1)
Collections are treated as types that apply to the documents within. That means that you can define a Collection and then create instances of this Collection in several databases. The same goes for graphs
In other words, you can have two databases cache_db and real_db each of them with an instance of a Users Collection. You can then be assured that documents of both collections will be subjected to the same validation rules. Ain’t that cool?
You can be 100% permissive or enforce schemas and validate fields, on set, on save or both.
Installation:¶
From PyPi:
pip install pyArango
For the latest version:
git clone https://github.com/tariqdaouda/pyArango.git
cd pyArango
python setup.py develop
Contents:¶
Connection¶
-
class
pyArango.connection.
AikidoSession
(username, password, verify=True, max_conflict_retries=5, max_retries=5, single_session=True, log_requests=False, pool_maxsize=10, timeout=30)[source]¶ Magical Aikido being that you probably do not need to access directly that deflects every http request to requests in the most graceful way. It will also save basic stats on requests in it’s attribute ‘.log’.
-
class
pyArango.connection.
Connection
(arangoURL='http://127.0.0.1:8529', username=None, password=None, verify=True, verbose=False, statsdClient=None, reportFileName=None, loadBalancing='round-robin', use_grequests=False, use_jwt_authentication=False, use_lock_for_reseting_jwt=True, max_retries=5, max_conflict_retries=5, pool_maxsize=10, timeout=30)[source]¶ This is the entry point in pyArango and directly handles databases. @param arangoURL: can be either a string url or a list of string urls to different coordinators @param use_grequests: allows for running concurent requets.
- arangoURL: list or str
- list of urls or url for connecting to the db
- username: str
- for credentials
- password: str
- for credentials
- verify: bool
- check the validity of the CA certificate
- verbose: bool
- flag for addictional prints during run
- statsdClient: instance
- statsd instance
- reportFileName: str
- where to save statsd report
- loadBalancing: str
- type of load balancing between collections
- use_grequests: bool
- parallelise requests using gevents. Use with care as gevents monkey patches python, this could have unintended concequences on other packages
- use_jwt_authentication: bool
- use JWT authentication
- use_lock_for_reseting_jwt: bool
- use lock for reseting gevents authentication
- max_retries: int
- max number of retries for a request
- max_conflict_retries: int
- max number of requests for a conflict error (1200 arangodb error). Does not work with gevents (grequests),
- pool_maxsize: int
- max number of open connections. (Not intended for grequest)
- timeout: int
- number of seconds to wait on a hanging connection before giving up
-
createDatabase
(name, **dbArgs)[source]¶ use dbArgs for arguments other than name. for a full list of arguments please have a look at arangoDB’s doc
-
hasDatabase
(name)[source]¶ returns true/false wether the connection has a database by the name of ‘name’
Database¶
-
class
pyArango.database.
Database
(connection, name)[source]¶ Databases are meant to be instanciated by connections
-
AQLQuery
(query, batchSize=100, rawResults=False, bindVars=None, options=None, count=False, fullCount=False, json_encoder=None, **moreArgs)[source]¶ Set rawResults = True if you want the query to return dictionnaries instead of Document objects. You can use **moreArgs to pass more arguments supported by the api, such as ttl=60 (time to live)
-
createCollection
(className='Collection', **colProperties)[source]¶ Creates a collection and returns it. ClassName the name of a class inheriting from Collection or Egdes, it can also be set to ‘Collection’ or ‘Edges’ in order to create untyped collections of documents or edges. Use colProperties to put things such as ‘waitForSync = True’ (see ArangoDB’s doc for a full list of possible arugments). If a ‘_properties’ dictionary is defined in the collection schema, arguments to this function overide it
-
createGraph
(name, createCollections=True, isSmart=False, numberOfShards=None, smartGraphAttribute=None, replicationFactor=None, writeConcern=None)[source]¶ Creates a graph and returns it. ‘name’ must be the name of a class inheriting from Graph. Checks will be performed to make sure that every collection mentionned in the edges definition exist. Raises a ValueError in case of a non-existing collection.
-
explainAQLQuery
(query, bindVars=None, allPlans=False)[source]¶ Returns an explanation of the query. Setting allPlans to True will result in ArangoDB returning all possible plans. False returns only the optimal plan
-
fetch_element
(aql_query, bind_vars=None, dont_raise_error_if_empty=False, default_output=None, logger=None, log_level=10)[source]¶ Fetch element by running a query.
- aql_query : str
- aql query string.
- bind_vars : dict, optional
- dictonary of bind variables (the default is None)
- dont_raise_error_if_empty: bool, optional
- do not raise error if the returned is empty. (the default is False)
- default_output: dict, optional
- default output if no value is returned. (the default is None)
- logger : Logger, optional
- logger to log the query and result. (the default is None means don’t log)
- log_level: Logger.loglevel, optional
- level of the log. (the default is logging.DEBUG)
- AQLFetchError
- When unable to fetch results or more than one 1 results returned.
- any
- an element returned by query.
-
fetch_list
(aql_query, bind_vars=None, batch_size=200, dont_raise_error_if_empty=False, logger=None, log_level=10)[source]¶ Fetch list of elements by running a query and merging all the batches.
- aql_query : str
- aql query string.
- bind_vars : dict, optional
- dictonary of bind variables (the default is None)
- batch_size : int, optional
- fetching batch size (the default is 200)
- dont_raise_error_if_empty: bool, optional
- do not raise error if the returned is empty. (the default is False)
- logger : Logger, optional
- logger to log the query and result. (the default is None means don’t log)
- log_level: Logger.loglevel, optional
- level of the log. (the default is logging.DEBUG)
- AQLFetchError
- When unable to fetch results
- list(any)
- a list returned by query.
-
fetch_list_as_batches
(aql_query, bind_vars=None, batch_size=200, dont_raise_error_if_empty=False, logger=None, log_level=10)[source]¶ Fetch list of elements as batches by running the query.
Generator which yeilds each batch as result.
- aql_query : str
- aql query string.
- bind_vars : dict, optional
- dictonary of bind variables (the default is None)
- batch_size : int, optional
- fetching batch size (the default is 200)
- dont_raise_error_if_empty: bool, optional
- do not raise error if the returned is empty. (the default is False)
- logger : Logger, optional
- logger to log the query and result. (the default is None means don’t log)
- log_level: Logger.loglevel, optional
- level of the log. (the default is logging.DEBUG)
- AQLFetchError
- When unable to fetch results
- list(any)
- a list returned by query.
-
no_fetch_run
(aql_query, bind_vars=None, logger=None, log_level=10)[source]¶ Run query which doesn’t have a return.
- aql_query : str
- aql query string.
- bind_vars : dict, optional
- dictonary of bind variables (the default is None)
- logger : Logger, optional
- logger to log the query and result. (the default is None means don’t log)
- log_level: Logger.loglevel, optional
- level of the log. (the default is logging.DEBUG)
- AQLFetchError
- When able to fetch results.
-
Collection¶
-
class
pyArango.collection.
Collection
(database, jsonData)[source]¶ A document collection. Collections are meant to be instantiated by databases.
-
action
(method, action, **params)[source]¶ A generic ‘fct’ for interacting everything that does not have an assigned ‘fct’.
-
activateCache
(cacheSize)[source]¶ Activate the caching system.
Cached documents are only available through the __getitem__ interface.
-
bulkImport_json
(filename, onDuplicate='error', formatType='auto', **params)[source]¶ Bulk import from a file following the ArangoDB key-value format.
-
bulkImport_values
(filename, onDuplicate='error', **params)[source]¶ Bulk import from a file following the ArangoDB json format.
-
bulkSave
(docs, onDuplicate='error', **params)[source]¶ Parameter ‘docs’ must be either an iterable of documents or dictionaries.
This function will return the number of documents, created and updated, and will raise an UpdateError exception if there is at least one error. ‘params’ are any parameters from the ArangoDB documentation.
-
createDocument
(initDict=None)[source]¶ Create and return a completely empty document unless the initial document is set via ‘initDict’.
-
ensureFulltextIndex
(fields, minLength=None, name=None)[source]¶ Create a fulltext index if it does not already exist, then return it.
-
ensureGeoIndex
(fields, name=None)[source]¶ Create a geo index if it does not already exist, then return it.
-
ensureHashIndex
(fields, unique=False, sparse=True, deduplicate=False, name=None)[source]¶ Create a hash index if it does not already exist, then return it.
-
ensurePersistentIndex
(fields, unique=False, sparse=True, deduplicate=False, name=None)[source]¶ Create a persistent index if it does not already exist, then return it.
-
ensureSkiplistIndex
(fields, unique=False, sparse=True, deduplicate=False, name=None)[source]¶ Create a skiplist index if it does not already exist, then return it.
-
ensureTTLIndex
(fields, expireAfter, unique=False, sparse=True, name=None)[source]¶ Create a TTL index if it does not already exist, then return it.
-
fetchAll
(rawResults=False, **queryArgs)[source]¶ Returns all the documents in the collection. You can use the optinal arguments ‘skip’ and ‘limit’:
fetchAlll(limit = 3, shik = 10)
-
fetchByExample
(exampleDict, batchSize, rawResults=False, **queryArgs)[source]¶ ‘exampleDict’ should be something like {‘age’ : 28}.
-
fetchDocument
(key, rawResults=False, rev=None)[source]¶ Fetche a document from the collection given its key.
This function always goes straight to the db and bypasses the cache. If you want to take advantage of the cache use the ‘__getitem__’ interface: collection[key]
-
fetchFirstExample
(exampleDict, rawResults=False)[source]¶ ‘exampleDict’ should be something like {‘age’ : 28}.
Return the first example found that matches the example, still in a ‘SimpleQuery’ object.
-
getIndexes
()[source]¶ Fill ‘self.indexes’ with all the indexes associated with the collection and return it.
-
getStatus
()[source]¶ Return a word describing the status of the collection (loaded, loading, deleted, unloaded, newborn) instead of a number, if you prefer the number it is in ‘self.status’.
-
getType
()[source]¶ Return a word describing the type of the collection (edges or ducments) instead of a number.
If you prefer the number it is in ‘self.type’.
-
classmethod
hasField
(fieldName)[source]¶ Return ‘True’ or ‘False’ whether the collection has field ‘K’ in its schema.
Use the dot notation for the nested fields: address.street
-
simpleQuery
(queryType, rawResults=False, **queryArgs)[source]¶ General interface for simple queries.
‘queryType’ takes the arguments known to the ArangoDB, for instance: ‘all’ or ‘by-example’. See the ArangoDB documentation for a list of valid ‘queryType’s. If ‘rawResults’ is set to ‘True’, the query will return dictionaries instead of ‘Document’ objetcs.
-
-
class
pyArango.collection.
Edges
(database, jsonData)[source]¶ The default edge collection. All edge Collections must inherit from it.
This one is meant to be called by the database.
-
getEdges
(vertex, inEdges=True, outEdges=True, rawResults=False)[source]¶ Return in, out, or both edges linked to a given document.
Vertex can be either a ‘Document’ object or a string for an ‘_id’. If ‘rawResults’ is set to ‘True’, return the results just as fetched without any processing. Otherwise, return a list of Edge objects.
-
getInEdges
(vertex, rawResults=False)[source]¶ An alias for ‘getEdges()’ that returns only the in ‘Edges’.
-
-
class
pyArango.collection.
Field
(validators=None, default=None)[source]¶ The class for defining pyArango fields.
Validators must be a list of validators.
‘default’ can also be a callable.
-
class
pyArango.collection.
DocumentCache
(cacheSize)[source]¶ Document cache for collection, with insert, deletes and updates in O(1).
-
class
pyArango.collection.
Collection_metaclass
[source]¶ The metaclass that takes care of keeping a register of all collection types.
-
classmethod
getCollectionClass
(name)[source]¶ Return the class object of a collection given its ‘name’.
-
classmethod
isCollection
(name) → bool[source]¶ return ‘True’ or ‘False’ whether ‘name’ is the name of collection.
-
classmethod
-
pyArango.collection.
getCollectionClass
(name) → bool[source]¶ Return ‘True’ or ‘False’ whether ‘name’ is the name of collection.
-
pyArango.collection.
isCollection
(name) → bool[source]¶ Return ‘True’ or ‘False’ whether ‘name’ is the name of a document collection.
-
pyArango.collection.
isDocumentCollection
(name) → bool[source]¶ Return ‘True’ or ‘False’ whether ‘name’ is the name of a document collection.
Indexes¶
Document¶
-
class
pyArango.document.
DocumentStore
(collection, validators=None, initDct=None, patch=False, subStore=False, validateInit=False)[source]¶ Store all the data of a document in hierarchy of stores and handles validation. Does not store private information, these are in the document.
-
class
pyArango.document.
Document
(collection, jsonFieldInit=None, on_load_validation=False)[source]¶ The class that represents a document. Documents are meant to be instanciated by collections
-
getEdges
(edges, inEdges=True, outEdges=True, rawResults=False)[source]¶ returns in, out, or both edges linked to self belonging the collection ‘edges’. If rawResults a arango results will be return as fetched, if false, will return a liste of Edge objects
-
getOutEdges
(edges, rawResults=False)[source]¶ An alias for getEdges() that returns only the out Edges
-
getResponsibleShard
()[source]¶ If we’re working with an arangodb cluster, we can use this method to fetch where a document lives.
-
patch
(keepNull=True, **docArgs)[source]¶ Saves the document by only updating the modified fields. The default behaviour concening the keepNull parameter is the opposite of ArangoDB’s default, Null values won’t be ignored Use docArgs for things such as waitForSync = True
-
reset
(collection, jsonFieldInit=None, on_load_validation=False)[source]¶ replaces the current values in the document by those in jsonFieldInit
-
save
(waitForSync=False, **docArgs)[source]¶ Saves the document to the database by either performing a POST (for a new document) or a PUT (complete document overwrite). If you want to only update the modified fields use the .patch() function. Use docArgs to put things such as ‘waitForSync = True’ (for a full list cf ArangoDB’s doc). It will only trigger a saving of the document if it has been modified since the last save. If you want to force the saving you can use forceSave()
-
-
class
pyArango.document.
Edge
(edgeCollection, jsonFieldInit=None, on_load_validation=False)[source]¶ An Edge document
-
links
(fromVertice, toVertice, **edgeArgs)[source]¶ An alias to save that updates the _from and _to attributes. fromVertice and toVertice, can be either strings or documents. It they are unsaved documents, they will be automatically saved.
-
Users¶
Query¶
-
class
pyArango.query.
Query
(request, database, rawResults)[source]¶ This class is abstract and should not be instanciated. All query classes derive from it
If rawResults = True, the results will be returned as dictionaries instead of Document objects.
-
class
pyArango.query.
AQLQuery
(database, query, batchSize, bindVars, options, count, fullCount, rawResults=True, json_encoder=None, **moreArgs)[source]¶ AQL queries are attached to and instanciated by a database
-
class
pyArango.query.
SimpleQuery
(collection, queryType, rawResults, json_encoder=None, **queryArgs)[source]¶ Simple queries are attached to and instanciated by a collection
Graph¶
-
class
pyArango.graph.
Graph
(database, jsonInit)[source]¶ The class from witch all your graph types must derive
-
createEdge
(collectionName, _fromId, _toId, edgeAttributes, waitForSync=False)[source]¶ creates an edge between two documents
-
createVertex
(collectionName, docAttributes, waitForSync=False)[source]¶ adds a vertex to the graph and returns it
-
deleteVertex
(document, waitForSync=False)[source]¶ deletes a vertex from the graph as well as al linked edges
-
link
(definition, doc1, doc2, edgeAttributes, waitForSync=False)[source]¶ A shorthand for createEdge that takes two documents as input
-
traverse
(startVertex, **kwargs)[source]¶ Traversal! see: https://docs.arangodb.com/HttpTraversal/README.html for a full list of the possible kwargs. The function must have as argument either: direction = “outbout”/”any”/”inbound” or expander = “custom JS (see arangodb’s doc)”. The function can’t have both ‘direction’ and ‘expander’ as arguments.
-
Exceptions¶
-
exception
pyArango.theExceptions.
AQLFetchError
(err_message)[source]¶ Raised error when fetching the data.
Error when unable to fetch.
- err_message : str
- error message.
-
exception
pyArango.theExceptions.
AQLQueryError
(message, query, errors=None)[source]¶ Something went wrong with an aql query
-
exception
pyArango.theExceptions.
AbstractInstanciationError
(cls)[source]¶ Raised when someone tries to instanciate an abstract class
-
exception
pyArango.theExceptions.
BulkOperationError
(message)[source]¶ Something went wrong in one of the bulk operations. This error contains more errors
-
exception
pyArango.theExceptions.
ConnectionError
(message, URL, statusCode='', errors=None)[source]¶ Something went wrong with the connection
-
exception
pyArango.theExceptions.
CreationError
(message, errors=None)[source]¶ Something went wrong when creating something
-
exception
pyArango.theExceptions.
CursorError
(message, cursorId, errors=None)[source]¶ Something went wrong when trying to fetch data with a cursor
-
exception
pyArango.theExceptions.
DeletionError
(message, errors=None)[source]¶ Something went wrong when deleting something
-
exception
pyArango.theExceptions.
ExportError
(message, errors=None)[source]¶ Something went wrong using the export cursor
-
exception
pyArango.theExceptions.
IndexError
(message, errors=None)[source]¶ wasn’t able to get the index
-
exception
pyArango.theExceptions.
InvalidDocument
(errors)[source]¶ Raised when a Document does not respect schema/validation defined in its collection
-
exception
pyArango.theExceptions.
QueryError
(message, errors=None)[source]¶ Something went wrong with an aql query
-
exception
pyArango.theExceptions.
SchemaViolation
(collection, field, errors=None)[source]¶ Raised when someone tries to add a new field to an object belonging a to a Collection with enforced schema
-
exception
pyArango.theExceptions.
SimpleQueryError
(message, errors=None)[source]¶ Something went wrong with a simple query
-
exception
pyArango.theExceptions.
TransactionError
(message, action, errors=None)[source]¶ Something went wrong with a transaction
-
exception
pyArango.theExceptions.
TraversalError
(message, errors=None)[source]¶ Something went wrong when doing a graph traversal
-
exception
pyArango.theExceptions.
UniqueConstrainViolation
(message, errors=None)[source]¶ Violation of a unique key
-
exception
pyArango.theExceptions.
UpdateError
(message, errors=None)[source]¶ Something went wrong when updating something
Validation¶
-
class
pyArango.validation.
Email
(*args, **kwrags)[source]¶ Checks if the field contains an emailaddress
-
class
pyArango.validation.
Length
(minLen, maxLen)[source]¶ validates that the value length is between given bounds
-
class
pyArango.validation.
NotNull
(reject_zero=False, reject_empty_string=True)[source]¶ Checks that the Field has a non null value. False is not considered a Null Value
Admin¶
CA Certificate¶
Foxx¶
All foxx related methods.
JW Auth¶
Tasks¶
All Task related methods.