flask-weaviate


Nameflask-weaviate JSON
Version 1.0.1 PyPI version JSON
download
home_page
SummaryFlask extension for Weaviate
upload_time2024-02-12 14:26:18
maintainer
docs_urlNone
author
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 No requirements were recorded.
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": "",
    "name": "flask-weaviate",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "flask,weaviate,flask-extension",
    "author": "",
    "author_email": "Evert Jan Stamhuis <ej@fromej.nl>",
    "download_url": "https://files.pythonhosted.org/packages/d4/16/285da82e216648ad9857c03f8a73801fcb9abc21c721c8f07e345db60567/flask_weaviate-1.0.1.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.0.1",
    "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": "53018424ecb7892915c44b1f3a192a5fb22e7c182d214ceb982bbcb63009f957",
                "md5": "48df3bd4ad954f899eed7e32df9b3721",
                "sha256": "de53f3d2e5d6999ca9ad6d4f442242c32f9f7f520e5ae05a147a7b05b4becdb8"
            },
            "downloads": -1,
            "filename": "flask_weaviate-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "48df3bd4ad954f899eed7e32df9b3721",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7643,
            "upload_time": "2024-02-12T14:26:16",
            "upload_time_iso_8601": "2024-02-12T14:26:16.643397Z",
            "url": "https://files.pythonhosted.org/packages/53/01/8424ecb7892915c44b1f3a192a5fb22e7c182d214ceb982bbcb63009f957/flask_weaviate-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d416285da82e216648ad9857c03f8a73801fcb9abc21c721c8f07e345db60567",
                "md5": "4b473c2ec2981c0a2c97661652944bb7",
                "sha256": "a9423fcd43e3de58172390a3fcba422d7a4467bfaa33092f9c246a539a267cc0"
            },
            "downloads": -1,
            "filename": "flask_weaviate-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4b473c2ec2981c0a2c97661652944bb7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7559,
            "upload_time": "2024-02-12T14:26:18",
            "upload_time_iso_8601": "2024-02-12T14:26:18.321582Z",
            "url": "https://files.pythonhosted.org/packages/d4/16/285da82e216648ad9857c03f8a73801fcb9abc21c721c8f07e345db60567/flask_weaviate-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-12 14:26:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "evertjstam",
    "github_project": "flask-weaviate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "flask-weaviate"
}
        
Elapsed time: 0.17968s