Flask extension for Weaviate
Project description
Flask-Weaviate
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35d1601c291cf6458bad70f9d4e1da35a439ace5f59fc2af5f367db9ffd09804
|
|
| MD5 |
6fd9df93c3076f9f453cb5ca0050fc1b
|
|
| BLAKE2b-256 |
3396a007d3fd4aada1001e8bbdc977f0c58aa88bb9126592af77697ba2564189
|
Provenance
The following attestation bundles were made for flask_weaviate-1.1.0.tar.gz:
Publisher:
python-publish.yml on evertjstam/flask-weaviate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flask_weaviate-1.1.0.tar.gz -
Subject digest:
35d1601c291cf6458bad70f9d4e1da35a439ace5f59fc2af5f367db9ffd09804 - Sigstore transparency entry: 155032940
- Sigstore integration time:
-
Permalink:
evertjstam/flask-weaviate@8d11bac3715560919973e32598f21606c560e8b7 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/evertjstam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8d11bac3715560919973e32598f21606c560e8b7 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e080cc35ac8127d94ae4344dad31a3aaa917cb5af4043ce92e34b8f73826a9ee
|
|
| MD5 |
715d5593a495773ff98462bb3e33a1c6
|
|
| BLAKE2b-256 |
cf6d72c3701d3d38a9eaafc44247d5013181e90d35e0ff132ce41925ad5a4e65
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flask_weaviate-1.1.0-py3-none-any.whl -
Subject digest:
e080cc35ac8127d94ae4344dad31a3aaa917cb5af4043ce92e34b8f73826a9ee - Sigstore transparency entry: 155032941
- Sigstore integration time:
-
Permalink:
evertjstam/flask-weaviate@8d11bac3715560919973e32598f21606c560e8b7 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/evertjstam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8d11bac3715560919973e32598f21606c560e8b7 -
Trigger Event:
release
-
Statement type: