Flask-arango-orm is used to connect to an ArangoDB instance using arango-orm as an object model layer to your Flask app. ArangoDB is a hybrid database that can provide a document, graph, and relational mode which can be taken advantage of using arango-orm.
Using pip:
pip install Flask-arango-ormUsing Poetry:
poetry add Flask-arango-ormTests can be ran using:
poetry run pytestDocumentation can be generated using:
make -C docs htmlThe extension integrates arango-orm with your Flask application. A modern
create_app factory can load configuration from environment variables using
the :class:`~flask_arango_orm.config.ArangoSettings` helper:
from flask import Flask
from flask_arango_orm import ArangoORM, ArangoSettings
def create_app() -> Flask:
app = Flask(__name__)
settings = ArangoSettings.from_env()
app.config.update(
ARANGODB_DATABASE=settings.database,
ARANGODB_USER=settings.user,
ARANGODB_PASSWORD=settings.password,
ARANGODB_HOST=settings.host,
ARANGODB_CLUSTER=settings.cluster,
ARANGODB_HOST_POOL=settings.host_pool,
)
arango = ArangoORM(app)
@app.route('/route')
def some_route():
# ``db_conn`` is an ``arango_orm.database.Database`` instance
db_conn = arango.connection
return 'ok'
return appTo work with an ArangoDB cluster enable ARANGODB_CLUSTER and provide
ARANGODB_HOST_POOL with the coordinator URLs. The extension uses
python-arango's ArangoClient to create a connection pool. The
connection property returns the next Database instance from this
pool.
def create_app() -> Flask:
app = Flask(__name__)
pool = [
('http', 'coordinator1', 8529),
('http', 'coordinator2', 8529),
]
app.config.update(
ARANGODB_CLUSTER=True,
ARANGODB_HOST_POOL=pool,
)
ArangoORM(app)
return appAsyncArangoORM works the same way when writing async routes. Retrieve the
connection with await:
from flask import Flask
from flask_arango_orm import AsyncArangoORM
app = Flask(__name__)
arango = AsyncArangoORM(app)
@app.get("/async")
async def async_route():
db = await arango.connection()
return "ok"flask_arango_orm uses the standard :mod:`logging` package. The
flask_arango_orm.arango module exposes a logger named after the module,
which reports connection attempts, successful connections and when connections
are torn down. Enable it with:
import logging logging.basicConfig(level=logging.INFO)