Skip to main content

Flask extension for Weaviate

Project description

Flask-Weaviate

PyPI Version Code Coverage 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:

pip install flask-weaviate

Usage

Initialize the extension in your Flask app:

from flask import Flask
from flask_weaviate import FlaskWeaviate

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

Access the Weaviate client within your Flask app:

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:

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

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 file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_weaviate-1.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_weaviate-1.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file flask_weaviate-1.1.0.tar.gz.

File metadata

  • Download URL: flask_weaviate-1.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for flask_weaviate-1.1.0.tar.gz
Algorithm Hash digest
SHA256 35d1601c291cf6458bad70f9d4e1da35a439ace5f59fc2af5f367db9ffd09804
MD5 6fd9df93c3076f9f453cb5ca0050fc1b
BLAKE2b-256 3396a007d3fd4aada1001e8bbdc977f0c58aa88bb9126592af77697ba2564189

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_weaviate-1.1.0.tar.gz:

Publisher: python-publish.yml on evertjstam/flask-weaviate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_weaviate-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: flask_weaviate-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for flask_weaviate-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e080cc35ac8127d94ae4344dad31a3aaa917cb5af4043ce92e34b8f73826a9ee
MD5 715d5593a495773ff98462bb3e33a1c6
BLAKE2b-256 cf6d72c3701d3d38a9eaafc44247d5013181e90d35e0ff132ce41925ad5a4e65

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_weaviate-1.1.0-py3-none-any.whl:

Publisher: python-publish.yml on evertjstam/flask-weaviate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page