Skip to main content

Inspira is a lightweight framework for building asynchronous web applications.

Project description

Inspira

License

Inspira is a lightweight framework for building asynchronous web applications.

Quick Start

Prerequisites

Make sure you have Python and pip installed on your system.

Create a Python Virtual Environment

# Create a new directory for your project
mkdir myproject
cd myproject

Create and activate a virtual environment

python -m venv venv
source venv/bin/activate   # On Windows, use `venv\Scripts\activate`

Install Inspira

pip install inspira

Generating an App

To generate a new app for your project, run the following command:

inspira init

Generate Database file

Use the following command to generate a database file:

inspira new database --name mydb --type sqlite

This command will create a new database file named mydb with SQLite as the database type.

The generated database file (database.py) will typically contain initial configurations and may look like this:

from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker

engine = create_engine("sqlite:///mydb.db")
db_session = scoped_session(
    sessionmaker(autocommit=False, autoflush=False, bind=engine)
)
Base = declarative_base()
Base.query = db_session.query_property()


def init_db():
    Base.metadata.create_all(bind=engine)

Generating Modules

To generate necessary resources for your project, run the following command:

inspira new module orders

Generated Directory Structure

After running the command to generate a new module (inspira new module orders), the directory structure of your project should look like the following:

├── app.py
├── database.py
└── src
    └── orders
        ├── __init__.py
        ├── order.py
        ├── order_controller.py
        └── order_repository.py
        └── order_service.py

Starting the Server

After generating your app and setting up the necessary resources, start the server with the following command:

uvicorn app:app --reload

Sessions

Inside app.py, after initializing Inspira instance:

app.session_type = "cookie"

Example 1: Setting a Session

@get("/")
async def set_session_data(request):
    context = {"variable": "value"}
    request.set_session("key", 23)

    return JsonResponse(context)

Example 2: Retrieving Session Data

@get("/")
async def get_session_data(request):
    context = {"variable": "value"}
    request.get_session("key")

    return JsonResponse(context)

Example 3: Removing Session Data

@get("/")
async def remove_session_data(request):
    context = {"variable": "value"}
    request.remove_session("key")

    return JsonResponse(context)

License

This project is licensed under the terms of the MIT license.

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

inspira-0.0.1.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

inspira-0.0.1-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file inspira-0.0.1.tar.gz.

File metadata

  • Download URL: inspira-0.0.1.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for inspira-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f29c6d6412ab55152f4d43602a58ec785855443a39f2980a6de27f8fbb9e37dd
MD5 27bebb538e69abd8fad3123e5f06e843
BLAKE2b-256 5eb7c30bd55910da2136f57f909ba9e78ae35d7ddc5bd697c81fd42d2defd021

See more details on using hashes here.

File details

Details for the file inspira-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: inspira-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for inspira-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5dcc473ef8bc88a0ae2c102bd81866298892947275dd4b35894f272dfbdc22bd
MD5 1e4ee529287b249d33711c50d9a57db6
BLAKE2b-256 370205874c12e70e901aba69b935633008a55021ad07d0be024256b069d41853

See more details on using hashes here.

Supported by

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