Skip to content

Commit

Permalink
version 0.0.1 (#1)
Browse files Browse the repository at this point in the history
* inital version

* following Flask Extension Development guideline

* fix typo
  • Loading branch information
zvfvrv authored May 7, 2020
1 parent 653ced2 commit f9c2514
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# flask-python-arango
# Flask-Python-Arango

python-arango support for Flask applications

## Installation

Install the extension with using pip, or easy_install.

.. code:: bash

$ pip install -U flask-python-arango

## Usage

## Contributing

Please create an issue on [Github](https://github.com/zvfvrv/flask-python-arango).
69 changes: 69 additions & 0 deletions flask_python_arango/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2020 Francesco Lombardo <[email protected]>

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = ("FlaskArango")

from arango import ArangoClient
from flask import current_app, _app_ctx_stack


class FlaskArango(object):

"""Manages ArangoDB connections for your Flask app.
FlaskArango objects provide access to ArangoDB MongoDB server via the :attr:`db`
attribute. You must either pass the :class:`~flask.Flask`
app to the constructor, or call :meth:`init_app`.
"""

def __init__(self, app=None):
if app is not None:
self.init_app(app)

def init_app(self, app):
self.app = app
app.teardown_appcontext(self.teardown)

def connect(self):

host = self.app.config.get("ARANGODB_HOST", None)
db_name = self.app.config.get("ARANGODB_DB", None)
db_username = self.app.config.get("ARANGODB_USERNAME", None)
db_password = self.app.config.get("ARANGODB_PSW", None)

if host is None:
raise ValueError(
"You must set the ARANGO_HOST Flask config variable",
)
if db_name is None:
raise ValueError(
"You must set the ARANGODB_DB Flask config variable",
)
# Initialize the client for ArangoDB.
client = ArangoClient(hosts=host)
# Connect to database.
return client.db(
db_name, username=db_username, password=db_password)

def teardown(self, exception):
ctx = _app_ctx_stack.top
if hasattr(ctx, 'arango_db'):
del ctx.arango_db

@property
def connection(self):
ctx = _app_ctx_stack.top
if ctx is not None:
if not hasattr(ctx, 'arango_db'):
ctx.arango_db = self.connect()
return ctx.arango_db
13 changes: 13 additions & 0 deletions flask_python_arango/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Francesco Lombardo <[email protected]>

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
51 changes: 51 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Flask-Python-Arango
-------------
ArangoDB support for Flask applications.
Flask-Python-Arango is pip-installable:
$ pip install Flask-Python-Arango
Source code is hosted on `GitHub <https://github.com/zvfvrv/flask-python-arango>`.
Contributions are welcome!
"""

from setuptools import find_packages, setup

with open("README.md", "r") as fh:
long_description = fh.read()

setup(
name="Flask-Python-Arango",
version="0.0.1",
url="https://github.com/zvfvrv/flask-python-arango",
download_url="https://github.com/zvfvrv/flask-python-arango/tags",
license="Apache-2.0",
author="Francesco Lombardo",
author_email="[email protected]",
description="Python ArangoDB support for Flask applications",
long_description=long_description,
zip_safe=False,
platforms="any",
packages=find_packages(),
install_requires=[
"Flask>=0.12",
"python-arango>=5.4.0",
"six",
],
classifiers=[
"Environment :: Web Environment",
"Framework :: Flask",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules"
],

)

0 comments on commit f9c2514

Please sign in to comment.