Skip to content

Commit f9c2514

Browse files
authored
version 0.0.1 (#1)
* inital version * following Flask Extension Development guideline * fix typo
1 parent 653ced2 commit f9c2514

4 files changed

Lines changed: 149 additions & 1 deletion

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
# flask-python-arango
1+
# Flask-Python-Arango
2+
23
python-arango support for Flask applications
4+
5+
## Installation
6+
7+
Install the extension with using pip, or easy_install.
8+
9+
.. code:: bash
10+
11+
$ pip install -U flask-python-arango
12+
13+
## Usage
14+
15+
## Contributing
16+
17+
Please create an issue on [Github](https://github.com/zvfvrv/flask-python-arango).

flask_python_arango/__init__.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2020 Francesco Lombardo <franclombardo@gmail.com>
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__all__ = ("FlaskArango")
16+
17+
from arango import ArangoClient
18+
from flask import current_app, _app_ctx_stack
19+
20+
21+
class FlaskArango(object):
22+
23+
"""Manages ArangoDB connections for your Flask app.
24+
FlaskArango objects provide access to ArangoDB MongoDB server via the :attr:`db`
25+
attribute. You must either pass the :class:`~flask.Flask`
26+
app to the constructor, or call :meth:`init_app`.
27+
"""
28+
29+
def __init__(self, app=None):
30+
if app is not None:
31+
self.init_app(app)
32+
33+
def init_app(self, app):
34+
self.app = app
35+
app.teardown_appcontext(self.teardown)
36+
37+
def connect(self):
38+
39+
host = self.app.config.get("ARANGODB_HOST", None)
40+
db_name = self.app.config.get("ARANGODB_DB", None)
41+
db_username = self.app.config.get("ARANGODB_USERNAME", None)
42+
db_password = self.app.config.get("ARANGODB_PSW", None)
43+
44+
if host is None:
45+
raise ValueError(
46+
"You must set the ARANGO_HOST Flask config variable",
47+
)
48+
if db_name is None:
49+
raise ValueError(
50+
"You must set the ARANGODB_DB Flask config variable",
51+
)
52+
# Initialize the client for ArangoDB.
53+
client = ArangoClient(hosts=host)
54+
# Connect to database.
55+
return client.db(
56+
db_name, username=db_username, password=db_password)
57+
58+
def teardown(self, exception):
59+
ctx = _app_ctx_stack.top
60+
if hasattr(ctx, 'arango_db'):
61+
del ctx.arango_db
62+
63+
@property
64+
def connection(self):
65+
ctx = _app_ctx_stack.top
66+
if ctx is not None:
67+
if not hasattr(ctx, 'arango_db'):
68+
ctx.arango_db = self.connect()
69+
return ctx.arango_db
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2020 Francesco Lombardo <franclombardo@gmail.com>
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

setup.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Flask-Python-Arango
3+
-------------
4+
5+
ArangoDB support for Flask applications.
6+
7+
Flask-Python-Arango is pip-installable:
8+
9+
$ pip install Flask-Python-Arango
10+
11+
Source code is hosted on `GitHub <https://github.com/zvfvrv/flask-python-arango>`.
12+
Contributions are welcome!
13+
"""
14+
15+
from setuptools import find_packages, setup
16+
17+
with open("README.md", "r") as fh:
18+
long_description = fh.read()
19+
20+
setup(
21+
name="Flask-Python-Arango",
22+
version="0.0.1",
23+
url="https://github.com/zvfvrv/flask-python-arango",
24+
download_url="https://github.com/zvfvrv/flask-python-arango/tags",
25+
license="Apache-2.0",
26+
author="Francesco Lombardo",
27+
author_email="franclombardo@gmail.com",
28+
description="Python ArangoDB support for Flask applications",
29+
long_description=long_description,
30+
zip_safe=False,
31+
platforms="any",
32+
packages=find_packages(),
33+
install_requires=[
34+
"Flask>=0.12",
35+
"python-arango>=5.4.0",
36+
"six",
37+
],
38+
classifiers=[
39+
"Environment :: Web Environment",
40+
"Framework :: Flask",
41+
"Intended Audience :: Developers",
42+
"Operating System :: OS Independent",
43+
"Programming Language :: Python :: 3.5",
44+
"Programming Language :: Python :: 3.6",
45+
"Programming Language :: Python :: 3.7",
46+
"Programming Language :: Python",
47+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
48+
"Topic :: Software Development :: Libraries :: Python Modules"
49+
],
50+
51+
)

0 commit comments

Comments
 (0)