Giter Club home page Giter Club logo

flask-deta's Introduction

flask-Deta Readme

Documentation Status PyPI Version License Downloads Dependencies GitHub Issues

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 See flask-deta on pypi

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.

Install

Installation through pip. See flask-deta on pypi

pip install flask-deta

QuickStart

  1. Create a Flask App: Begin by creating an instance of the Flask app in your Python code.

  2. Set Configuration Parameters: Set the required parameters, such as your Deta project key, Base name, and Drive name.

  3. 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

flask-deta's People

Contributors

jesparzarom avatar

Stargazers

 avatar

Watchers

 avatar

flask-deta's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.