flask-weaviate


Nameflask-weaviate JSON
Version 1.1.0 PyPI version JSON
download
home_pageNone
SummaryFlask extension for Weaviate
upload_time2024-12-12 12:13:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseCopyright (c) 2024 Evert Jan Stamhuis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords flask weaviate flask-extension
VCS
bugtrack_url
requirements annotated-types anyio authlib blinker certifi cffi charset-normalizer click cryptography exceptiongroup flask grpcio grpcio-health-checking grpcio-tools h11 httpcore httpx idna importlib-metadata itsdangerous jinja2 markupsafe protobuf pycparser pydantic pydantic-core requests sniffio typing-extensions urllib3 validators weaviate-client werkzeug zipp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Flask-Weaviate

[![PyPI Version](https://img.shields.io/pypi/v/flask-weaviate.svg)](https://pypi.org/project/flask-weaviate/)
![Code Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)


Flask-Weaviate is a Flask extension for integrating Weaviate into Flask applications. It provides a convenient way to manage a Weaviate client connection, supporting configuration through Flask app settings and environment variables.

## Installation

Install Flask-Weaviate using pip:

```bash
pip install flask-weaviate
```

## Usage

Initialize the extension in your Flask app:

```python
from flask import Flask
from flask_weaviate import FlaskWeaviate

app = Flask(__name__)
weaviate = FlaskWeaviate(app)
```

Access the Weaviate client within your Flask app:

```python
weaviate_client = weaviate.client
# Now you can use weaviate_client to interact with Weaviate
```

Automatically disconnects the Weaviate client during app context teardown.

### Flask app factory:

```python
from flask import Flask, jsonify
from flask_weaviate import FlaskWeaviate

weaviate = FlaskWeaviate()

def create_app():
    app = Flask(__name__)
    weaviate.init_app(app)

    @app.route('/')
    def index():
        # Access the Weaviate client
        client = weaviate.client

        # Now you can use client to interact with Weaviate
        # ...

        return jsonify({'message': 'Hello, Weaviate!'})

    # Your other app configurations and extensions

    return app

if __name__ == '__main__':
    create_app().run()
```

## Configuration

The following configuration parameters can be set in the Flask app's configuration or as environment variables:

- `WEAVIATE_HTTP_HOST`: Weaviate server HTTP host.
- `WEAVIATE_HTTP_PORT`: Weaviate server HTTP port.
- `WEAVIATE_HTTP_SECURE`: Use HTTP secure connection to the Weaviate server (True/False).
- `WEAVIATE_GRPC_HOST`: Weaviate server gRPC host.
- `WEAVIATE_GRPC_PORT`: Weaviate server gRPC port.
- `WEAVIATE_GRPC_SECURE`: Use gRPC secure connection to the Weaviate server (True/False).
- `WEAVIATE_API_KEY`: API key for authentication with Weaviate.
- `WEAVIATE_USERNAME`: Username for authentication (used with password).
- `WEAVIATE_PASSWORD`: Password for authentication (used with username).
- `WEAVIATE_ACCESS_TOKEN`: Access token for authentication with Weaviate.
- `WEAVIATE_CONNECTION_PARAMS`: Weaviate client connection parameters.
- `WEAVIATE_EMBEDDED_OPTIONS`: Options for embedded Weaviate.
- `WEAVIATE_AUTH_CLIENT_SECRET`: Auth client secret for Weaviate.
- `WEAVIATE_ADDITIONAL_HEADERS`: Additional headers for Weaviate requests.
- `WEAVIATE_ADDITIONAL_CONFIG`: Additional configuration for Weaviate.
- `WEAVIATE_SKIP_INIT_CHECKS`: Skip Weaviate client initialization checks.

#### Connection

When any of `http_host` `http_port` `http_secure` `grpc_host` `grpc_port` `grpc_secure` is set, 
the connection is created with these values as connection params

Else if `connection_params` are given, they are used to connect

Else Weaviate is stared in Embedded mode standard (either with delivered `embedded_options` or defaults)

#### Authentication

Authentication is determined from sequence: `api_key`, `username + password`, `access_token`.
If the first in sequence is detected the others are skipped.

### Example

```python
from flask import Flask, jsonify
from flask_weaviate import FlaskWeaviate

app = Flask(__name__)
weaviate = FlaskWeaviate(
    app,
    http_host="weaviate-server",
    http_port=80,
    http_secure=False,
    api_key="your-api-key",
    skip_init_checks=True
)

@app.route('/')
def index():
    # Access the Weaviate client
    weaviate_client = weaviate.client

    # Now you can use weaviate_client to interact with Weaviate
    # ...

    return jsonify({'message': 'Hello, Weaviate!'})

if __name__ == '__main__':
    app.run()
```

## Teardown Function

Flask-Weaviate includes a teardown function to automatically disconnect the Weaviate client during app context teardown. This ensures proper cleanup of resources.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flask-weaviate",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flask, weaviate, flask-extension",
    "author": null,
    "author_email": "Evert Jan Stamhuis <ej@fromej.nl>",
    "download_url": "https://files.pythonhosted.org/packages/33/96/a007d3fd4aada1001e8bbdc977f0c58aa88bb9126592af77697ba2564189/flask_weaviate-1.1.0.tar.gz",
    "platform": null,
    "description": "# Flask-Weaviate\n\n[![PyPI Version](https://img.shields.io/pypi/v/flask-weaviate.svg)](https://pypi.org/project/flask-weaviate/)\n![Code Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n\nFlask-Weaviate is a Flask extension for integrating Weaviate into Flask applications. It provides a convenient way to manage a Weaviate client connection, supporting configuration through Flask app settings and environment variables.\n\n## Installation\n\nInstall Flask-Weaviate using pip:\n\n```bash\npip install flask-weaviate\n```\n\n## Usage\n\nInitialize the extension in your Flask app:\n\n```python\nfrom flask import Flask\nfrom flask_weaviate import FlaskWeaviate\n\napp = Flask(__name__)\nweaviate = FlaskWeaviate(app)\n```\n\nAccess the Weaviate client within your Flask app:\n\n```python\nweaviate_client = weaviate.client\n# Now you can use weaviate_client to interact with Weaviate\n```\n\nAutomatically disconnects the Weaviate client during app context teardown.\n\n### Flask app factory:\n\n```python\nfrom flask import Flask, jsonify\nfrom flask_weaviate import FlaskWeaviate\n\nweaviate = FlaskWeaviate()\n\ndef create_app():\n    app = Flask(__name__)\n    weaviate.init_app(app)\n\n    @app.route('/')\n    def index():\n        # Access the Weaviate client\n        client = weaviate.client\n\n        # Now you can use client to interact with Weaviate\n        # ...\n\n        return jsonify({'message': 'Hello, Weaviate!'})\n\n    # Your other app configurations and extensions\n\n    return app\n\nif __name__ == '__main__':\n    create_app().run()\n```\n\n## Configuration\n\nThe following configuration parameters can be set in the Flask app's configuration or as environment variables:\n\n- `WEAVIATE_HTTP_HOST`: Weaviate server HTTP host.\n- `WEAVIATE_HTTP_PORT`: Weaviate server HTTP port.\n- `WEAVIATE_HTTP_SECURE`: Use HTTP secure connection to the Weaviate server (True/False).\n- `WEAVIATE_GRPC_HOST`: Weaviate server gRPC host.\n- `WEAVIATE_GRPC_PORT`: Weaviate server gRPC port.\n- `WEAVIATE_GRPC_SECURE`: Use gRPC secure connection to the Weaviate server (True/False).\n- `WEAVIATE_API_KEY`: API key for authentication with Weaviate.\n- `WEAVIATE_USERNAME`: Username for authentication (used with password).\n- `WEAVIATE_PASSWORD`: Password for authentication (used with username).\n- `WEAVIATE_ACCESS_TOKEN`: Access token for authentication with Weaviate.\n- `WEAVIATE_CONNECTION_PARAMS`: Weaviate client connection parameters.\n- `WEAVIATE_EMBEDDED_OPTIONS`: Options for embedded Weaviate.\n- `WEAVIATE_AUTH_CLIENT_SECRET`: Auth client secret for Weaviate.\n- `WEAVIATE_ADDITIONAL_HEADERS`: Additional headers for Weaviate requests.\n- `WEAVIATE_ADDITIONAL_CONFIG`: Additional configuration for Weaviate.\n- `WEAVIATE_SKIP_INIT_CHECKS`: Skip Weaviate client initialization checks.\n\n#### Connection\n\nWhen any of `http_host` `http_port` `http_secure` `grpc_host` `grpc_port` `grpc_secure` is set, \nthe connection is created with these values as connection params\n\nElse if `connection_params` are given, they are used to connect\n\nElse Weaviate is stared in Embedded mode standard (either with delivered `embedded_options` or defaults)\n\n#### Authentication\n\nAuthentication is determined from sequence: `api_key`, `username + password`, `access_token`.\nIf the first in sequence is detected the others are skipped.\n\n### Example\n\n```python\nfrom flask import Flask, jsonify\nfrom flask_weaviate import FlaskWeaviate\n\napp = Flask(__name__)\nweaviate = FlaskWeaviate(\n    app,\n    http_host=\"weaviate-server\",\n    http_port=80,\n    http_secure=False,\n    api_key=\"your-api-key\",\n    skip_init_checks=True\n)\n\n@app.route('/')\ndef index():\n    # Access the Weaviate client\n    weaviate_client = weaviate.client\n\n    # Now you can use weaviate_client to interact with Weaviate\n    # ...\n\n    return jsonify({'message': 'Hello, Weaviate!'})\n\nif __name__ == '__main__':\n    app.run()\n```\n\n## Teardown Function\n\nFlask-Weaviate includes a teardown function to automatically disconnect the Weaviate client during app context teardown. This ensures proper cleanup of resources.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2024 Evert Jan Stamhuis  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Flask extension for Weaviate",
    "version": "1.1.0",
    "project_urls": {
        "documentation": "https://github.com/evertjstam/flask-weaviate",
        "homepage": "https://github.com/evertjstam/flask-weaviate",
        "repository": "https://github.com/evertjstam/flask-weaviate",
        "tracker": "https://github.com/evertjstam/flask-weaviate/issues"
    },
    "split_keywords": [
        "flask",
        " weaviate",
        " flask-extension"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf6d72c3701d3d38a9eaafc44247d5013181e90d35e0ff132ce41925ad5a4e65",
                "md5": "715d5593a495773ff98462bb3e33a1c6",
                "sha256": "e080cc35ac8127d94ae4344dad31a3aaa917cb5af4043ce92e34b8f73826a9ee"
            },
            "downloads": -1,
            "filename": "flask_weaviate-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "715d5593a495773ff98462bb3e33a1c6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7614,
            "upload_time": "2024-12-12T12:13:48",
            "upload_time_iso_8601": "2024-12-12T12:13:48.943940Z",
            "url": "https://files.pythonhosted.org/packages/cf/6d/72c3701d3d38a9eaafc44247d5013181e90d35e0ff132ce41925ad5a4e65/flask_weaviate-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3396a007d3fd4aada1001e8bbdc977f0c58aa88bb9126592af77697ba2564189",
                "md5": "6fd9df93c3076f9f453cb5ca0050fc1b",
                "sha256": "35d1601c291cf6458bad70f9d4e1da35a439ace5f59fc2af5f367db9ffd09804"
            },
            "downloads": -1,
            "filename": "flask_weaviate-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6fd9df93c3076f9f453cb5ca0050fc1b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7519,
            "upload_time": "2024-12-12T12:13:50",
            "upload_time_iso_8601": "2024-12-12T12:13:50.295412Z",
            "url": "https://files.pythonhosted.org/packages/33/96/a007d3fd4aada1001e8bbdc977f0c58aa88bb9126592af77697ba2564189/flask_weaviate-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-12 12:13:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "evertjstam",
    "github_project": "flask-weaviate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "annotated-types",
            "specs": [
                [
                    "==",
                    "0.6.0"
                ]
            ]
        },
        {
            "name": "anyio",
            "specs": [
                [
                    "==",
                    "4.2.0"
                ]
            ]
        },
        {
            "name": "authlib",
            "specs": [
                [
                    "==",
                    "1.3.0"
                ]
            ]
        },
        {
            "name": "blinker",
            "specs": [
                [
                    "==",
                    "1.7.0"
                ]
            ]
        },
        {
            "name": "certifi",
            "specs": [
                [
                    "==",
                    "2024.2.2"
                ]
            ]
        },
        {
            "name": "cffi",
            "specs": [
                [
                    "==",
                    "1.16.0"
                ]
            ]
        },
        {
            "name": "charset-normalizer",
            "specs": [
                [
                    "==",
                    "3.3.2"
                ]
            ]
        },
        {
            "name": "click",
            "specs": [
                [
                    "==",
                    "8.1.7"
                ]
            ]
        },
        {
            "name": "cryptography",
            "specs": [
                [
                    "==",
                    "42.0.2"
                ]
            ]
        },
        {
            "name": "exceptiongroup",
            "specs": [
                [
                    "==",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "flask",
            "specs": [
                [
                    "==",
                    "3.0.2"
                ]
            ]
        },
        {
            "name": "grpcio",
            "specs": [
                [
                    "==",
                    "1.60.1"
                ]
            ]
        },
        {
            "name": "grpcio-health-checking",
            "specs": [
                [
                    "==",
                    "1.60.1"
                ]
            ]
        },
        {
            "name": "grpcio-tools",
            "specs": [
                [
                    "==",
                    "1.60.1"
                ]
            ]
        },
        {
            "name": "h11",
            "specs": [
                [
                    "==",
                    "0.14.0"
                ]
            ]
        },
        {
            "name": "httpcore",
            "specs": [
                [
                    "==",
                    "1.0.2"
                ]
            ]
        },
        {
            "name": "httpx",
            "specs": [
                [
                    "==",
                    "0.26.0"
                ]
            ]
        },
        {
            "name": "idna",
            "specs": [
                [
                    "==",
                    "3.6"
                ]
            ]
        },
        {
            "name": "importlib-metadata",
            "specs": [
                [
                    "==",
                    "7.0.1"
                ]
            ]
        },
        {
            "name": "itsdangerous",
            "specs": [
                [
                    "==",
                    "2.1.2"
                ]
            ]
        },
        {
            "name": "jinja2",
            "specs": [
                [
                    "==",
                    "3.1.3"
                ]
            ]
        },
        {
            "name": "markupsafe",
            "specs": [
                [
                    "==",
                    "2.1.5"
                ]
            ]
        },
        {
            "name": "protobuf",
            "specs": [
                [
                    "==",
                    "4.25.2"
                ]
            ]
        },
        {
            "name": "pycparser",
            "specs": [
                [
                    "==",
                    "2.21"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    "==",
                    "2.6.1"
                ]
            ]
        },
        {
            "name": "pydantic-core",
            "specs": [
                [
                    "==",
                    "2.16.2"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "sniffio",
            "specs": [
                [
                    "==",
                    "1.3.0"
                ]
            ]
        },
        {
            "name": "typing-extensions",
            "specs": [
                [
                    "==",
                    "4.9.0"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.2.0"
                ]
            ]
        },
        {
            "name": "validators",
            "specs": [
                [
                    "==",
                    "0.22.0"
                ]
            ]
        },
        {
            "name": "weaviate-client",
            "specs": [
                [
                    "==",
                    "4.4.2"
                ]
            ]
        },
        {
            "name": "werkzeug",
            "specs": [
                [
                    "==",
                    "3.0.1"
                ]
            ]
        },
        {
            "name": "zipp",
            "specs": [
                [
                    "==",
                    "3.17.0"
                ]
            ]
        }
    ],
    "lcname": "flask-weaviate"
}
        
Elapsed time: 0.41330s