A Python library for seamless integration with DetaSpace in Flask
Project description
Version 0.2.1
⚠️ This is the initial version 0.2.1 and is currently in the alpha stage. It is not recommended for production use.
Welcome to FlaskDeta README!
For a more detailed use, I recommend you to visit the Flask-Deta documentation
Flask-Deta is a Python library that simplifies the integration of your DetaSpace collection of database and/or drive files with Flask framework.
With Flask-Deta, you can store and manage data with DetaBase
and handle file storage operations with DetaDrive
, all within the context of your Flask application. This robust combination allows you to leverage the secure and scalable cloud infrastructure of DetaSpace, making data and file management for your web projects convenient.
In this documents, we will provide you with an in-depth overview of Flask-Deta and help you get started using this extraordinary tool.
We'd like to inform you that not all DetaSpace functionalities are currently integrated, both in Drive and Base. However, we are working on gradually incorporating them to create a robust integration package between Flask and DetaSpace. Our aim is to enhance your development experience by leveraging the full potential of this integration.
- To learn more about DetaSpace visit the DetaSpace documentation.
- To learn more about Flask visit the Flask documentation.
Install
pip install flask-deta
QuickStart
-
Create a Flask App: Begin by creating an instance of the Flask app in your Python code.
-
Set Configuration Parameters: Set the required parameters, such as your Deta project key, Base name, and Drive name.
-
Create DetaBase and DetaDrive Instances: Create instances of DetaBase and DetaDrive using your Flask
app
as an argument.
DetaBase
from flask import Flask
from flask_deta import DetaBase
app = Flask(__name__)
# Set the DetaSpace project key and database name
app.config["DETA_PROJECT_KEY"] = "MyKey12345"
app.config["BASE_NAME"] = "products" # DetaSpace Base for data
# Create instance of DetaBase
base = DetaBase(app)
# DetaBase.get_all()
@app.route("/data")
def all_records():
data = base.get_all()
return data
if __name__ == "__main__":
app.run(debug=True)
DetaDrive
from flask import Flask
from flask_deta import DetaDrive
app = Flask(__name__)
# Set the DetaSpace project key and drive name
app.config["DETA_PROJECT_KEY"] = "MyKey12345"
app.config["DRIVE_NAME"] = "icons" # DetaSpace Drive for files
# Create instances of DetaDrive
drive = DetaDrive(app)
# DetaDrive.all_files()
@app.route("/files")
def all_files():
files = drive.all_files()
return files
if __name__ == "__main__":
app.run(debug=True)
DetaDrive + DetaBase
from flask import Flask
from flask_deta import DetaBase, DetaDrive
app = Flask(__name__)
# Set the DetaSpace project key, database name and drive name
app.config["DETA_PROJECT_KEY"] = "MyKey12345"
app.config["BASE_NAME"] = "products" # DetaSpace Base for data
app.config["DRIVE_NAME"] = "icons" # DetaSpace Drive for files
# Create instances of DetaDrive and DetaBase
base = DetaBase(app)
drive = DetaDrive(app)
# DetaBase.get_all()
@app.route("/data")
def all_records():
data = base.get_all()
return data
# DetaDrive.all_files()
@app.route("/files")
def all_files():
files = drive.all_files()
return files
if __name__ == "__main__":
app.run(debug=True)
Using init_app()
To ensure modularity and easy integration, the init_app()
method is provided for initializing both DetaBase and DetaDrive separately. This approach allows you to configure and associate the extensions with your Flask application in a standardized manner.
DetaBase.init_app
from flask import Flask
from flask_deta import DetaBase
app = Flask(__name__)
# Set the DetaSpace project key and database name
app.config["DETA_PROJECT_KEY"] = "MyKey12345"
app.config["BASE_NAME"] = "products" # DetaSpace Base for data
# Create an instance of DetaBase
base = DetaBase()
@app.route("/all")
def all_data():
data = base.get_all()
return data
base.init_app(app)
if __name__ == "__main__":
app.run(debug=True)
DetaDrive.init_app
from flask import Flask
from flask_deta import DetaDrive
app = Flask(__name__)
# Set the DetaSpace project key and drive name
app.config["DETA_PROJECT_KEY"] = "MyKey12345"
app.config["DRIVE_NAME"] = "icons" # DetaSpace Drive for files
# Create an instance of DetaDrive
drive = DetaDrive()
@app.route("/files")
def files():
files = drive.all_files()
return files
drive.init_app(app)
if __name__ == "__main__":
app.run(debug=True)
DetaBase.init_app + DetaDrive.init_app
app = Flask(__name__)
# Set the DetaSpace project key and drive name
app.config["DETA_PROJECT_KEY"] = "MyKey12345"
app.config["BASE_NAME"] = "products" # DetaSpace Base for data
app.config["DRIVE_NAME"] = "icons" # DetaSpace Drive for files
# Create instances of DetaDrive and DetaBase
base = DetaBase()
drive = DetaDrive()
# Home
@app.route("/")
def home():
links = """
<head>
<title>Flask-Deta</title>
<style>
body {
background: antiquewhite;
color: white;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
color: darkslateblue;
}
a {
display: block;
margin: 10px auto;
padding: 10px;
width: 200px;
background-color: deepskyblue;
color: white;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease-in-out;
}
a:hover {
background-color: dodgerblue;
}
</style>
</head>
<body>
<h1>Welcome to Flask-Deta</h1>
<div>
<a href="/data" target="_blank">
Get all data list
</a>
<a href="/files" target="_blank">
Get all files list
</a>
</div>
</body>
"""
return links
# DetaBase.get_all()
@app.route("/data")
def all_records():
data = base.get_all()
return data
# DetaDrive.all_files()
@app.route("/files")
def all_files():
files = drive.all_files()
return files
base.init_app(app)
drive.init_app(app)
if __name__ == "__main__":
app.run(debug=True)
Visit the Flask-Deta documentation
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file flask_deta-0.2.1.tar.gz
.
File metadata
- Download URL: flask_deta-0.2.1.tar.gz
- Upload date:
- Size: 361.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0754801e6fa2d43035325723d803c0b401faa7718becf54214db11e5ce747edf |
|
MD5 | f996d6ec4b613658e5ee4186a620b4e6 |
|
BLAKE2b-256 | dca32523f3f4ccd8ecc1ba9e6ea980a06bd5d952dd542bc6ab6c3dd9d7477c81 |
File details
Details for the file flask_deta-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: flask_deta-0.2.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90cd51c622e23e472b76787595427c2e3085f404d2922de4ad9e97fc8b0e073f |
|
MD5 | e56b9888490ba445c8ae9e3ac6a7b68c |
|
BLAKE2b-256 | 9146d12807b50883419d9b6b5289e5b109e8c43f167017022e70d009073659e6 |