Skip to main content

🔥🔥🔥 Cloudoll

Quickly create web applications based on Python.

Documentation

Docs

Structure

Config

Middleware

Router

View

Cookie and Session

Upload file

WebSocket

Mysql

Deployment

Install

pip install cloudoll

Environment

  • Operating System: Supports macOS, Linux, Windows
  • Runtime Environment: Minimum requirement 3.6.0.

Quick Start

Now you can use cloudoll create myapp to create a new project, 3 steps to start:

  1. create a new project
$ cloudoll create myapp
  1. cd to project directory
$ cd myapp
  1. start dev server
cloudoll start -n myapp

You can also manually create a project step by step.

$ mkdir cloudoll-demo && cd cloudoll-demo
$ pip3 install cloudoll
$ vi app.py

app.py content:

## /app.py
from cloudoll.web import app


if __name__ == "__main__":
    app.create().run()

Controller

$ mkdir -p controllers/home
$ touch controllers/home/__init__.py
$ vi controllers/home/index.py

controllers/home/index.py content:

# /controllers/home/index.py
from cloudoll.web import get

@get('/')
async def home():
    return {"name": "cloudoll" ,"msg": "ok"}

run:

$ python3 app.py
$ open http://localhost:9001

Open in browser http://127.0.0.1:9001/

you can see the result:

{ 
    "name": "cloudoll" ,
    "msg": "ok" ,
    "timestamp": 1681993906410 
}

Congratulations, you have successfully written one Restful API with cloudoll.

Template rendering

In most cases, we need to read the data, render the template, and then present it to the user. Therefore, we need to introduce the corresponding template engine.

in this demo,we using Nunjucks to render template.

$ mkdir templates
$ vi templates/index.html

index.html contents:

<!-- /templates/index.html -->

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>
</head>
<body>
    <p>Hello {{name}}</p>
</body>
</html>

edit /controllers/home/index.py contents:

# /controllers/home/index.py
from cloudoll.web import get, render_view

@get('/')
async def home():
    data = {"name": "cloudoll" ,"msg": "ok"}
    return render_view("index.html",data)

at this time ,we can see “Hello cloudoll.

ok , we wrotten a view page.

static files

We want to embed static resources such as images, JS, and CSS in the template, which requires the use of static resources. We place these js, css, and image files in the static directory.

For online environments, it is recommended to deploy to a CDN or use servers like nginx.

$ mkdir -p static/img
$ mkdir -p static/js
$ mkdir -p static/css

in img directory ,we can put images resources.

make a new js file index.js ,contents:

clike the body , we can see the alert tip "hello world"

// /static/js/index.js
document.addEventListener('DOMContentLoaded',function(){
    document.body.addEventListener('click',function(){
        alert('hello cloudoll.')
    })
})

make a new css file index.css ,contents:

 /* /static/css/index.css */
html,
body {
  width: 100%;
  height: 100%;
  color: rgb(0, 229, 255);
  margin: 0;
  padding: 0;
}

edit the view page /templates/index.html ,in head we import the css file, like this:

<!-- /templates/index.html -->
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/png" href="/static/img/logo.png"/>
    <link rel="stylesheet" href="/static/css/index.css">
    <script src="/static/js/index.js"></script>
    <title>Home</title>
</head>
<body>
    <p>My name is {{name}}</p>
</body>
</html>

we create a config file, and config static resource.

$ mkdir config
$ vi config/conf.local.yaml

/config/conf.local.yaml contents:

server:
  static:
    prefix: /static

after reload the page , our changes will be reflected.

Middleware

Suppose there is a requirement: our news site prohibits access by Baidu crawlers.

so we need to write a middleware to check User-Agent. like this:

$ mkdir middlewares
$ vi middlewares/robot.py

edit middlewares/robot.py, contents:

# /middlewares/robot.py
from cloudoll.web import middleware, render_json
import re

@middleware()
def mid_robot():
    async def robot(request, handler):
        ua = request.headers.get('user-agent')
        if re.match('Baiduspider', ua):
            return render_json(status=403, text="Go away , robot.")
        return await handler(request)

    return robot

after restart the server, you can use curl http://localhost:9001/news -A "Baiduspider" to see the effect. we can see more information in Middleware

Configuration

When writing business logic, it is inevitable to have configuration files. Managing configurations through code involves adding configurations for multiple environments within the code, and passing the parameter of the current environment during startup.

cloudoll support loading configurations based on the environment, defining configuration files for multiple environments

config
|- conf.local.yaml
|- conf.prod.yaml
`- conf.test.yaml

now, we create a config file:

$ mkdir -p config/conf.local.yaml
$ vi config/conf.local.yaml

the flollowing is mysql and server's configuration:

server:
  host: 192.168.0.1
  port: 9001
  static: false
  client_max_size: 1024000
  static: 
    prefix: /static
    show_index: true
    append_version: true
    follow_symlinks: true
database:
  mysql:
    host: 127.0.0.1
    port: 3306
    user: root
    password: abcd
    db: blog
    charset: utf8mb4

the local will be used as default configuration, when you start your application, it will load the local configuration. like cloudoll start -n myapp -env local will load the conf.local.yaml configuration.

cli

Create model

export model from database

cloudoll gen -t users 

More parameters:

  • -p (--path) the path to save the model
  • -c (--create) to create model or create tables, default is create model
  • -t (--table) The model or table name to be generated, separated by ,, ALL for all tables
  • -env (--environment) to load the configuration file , default is local
  • -db (--database) Database instance name, depends on the configuration file, if there are multiple databases
  • -h (--help) help

Development and debugging

cloudoll start --name myapp -env local -m development

Production Environment

cloudoll start --name myapp -env prod --mode production

you can use clodoll stop myapp to stop your application , or use cloudoll restart myapp to restart your application. cloudoll list to see all your applications.

Metadata

Release files for cloudoll 3.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudoll 3.0.14
File Size Uploaded
cloudoll-3.0.14.tar.gz 45.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cloudoll 3.0.14
File Interpreter ABI Platform
cloudoll-3.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 96.8 kB

Release files / cloudoll-3.0.14.tar.gz

Download URL cloudoll-3.0.14.tar.gz
Size 45.4 kB
Tags Source
SHA-256 checksum
How to use checksums
402cc97c9e5c0eb9b5202c87fa4869740331cb4500b107b39df92580aeab3bfc
BLAKE2b-256 checksum
How to use checksums
fe3c28d871a48ab7f020b75ad45d53164d768d05e4dcc60d97200abff477328f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.12

Release files / cloudoll-3.0.14-py3-none-any.whl

Download URL cloudoll-3.0.14-py3-none-any.whl
Size 51.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
447aebc6c3acf6587437d2aa76a0fb4617e2faba00ad4072cc84a340db2c828a
BLAKE2b-256 checksum
How to use checksums
1cfe17d38250e1077c99be3b4c2984df006cb18a90586c6e2203834f8596770c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.12

Release history Release notifications | RSS feed

4.3.0

2 release files

4.2.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

This release

3.0.14 This release

2 release files

3.0.13

2 release files

3.0.12

2 release files

3.0.11

2 release files

3.0.10

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.4.0

3 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.38

2 release files

2.2.37

2 release files

2.2.36

2 release files

2.2.31

2 release files

2.2.30

2 release files

2.2.29

2 release files

2.2.28

2 release files

2.2.26

2 release files

2.2.24

2 release files

2.2.23

2 release files

2.2.20

2 release files

2.2.19

2 release files

2.2.18

2 release files

2.2.17

2 release files

2.2.14

2 release files

2.2.13

2 release files

2.2.12

2 release files

2.2.11

2 release files

2.2.10

2 release files

2.2.9

2 release files

2.2.8

2 release files

2.2.7

2 release files

2.2.6

2 release files

2.2.5

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.23

2 release files

2.0.22

2 release files

2.0.21

2 release files

2.0.20

2 release files

2.0.19

2 release files

2.0.18

2 release files

2.0.17

2 release files

2.0.16

2 release files

2.0.15

2 release files

2.0.14

2 release files

2.0.13

2 release files

2.0.12

2 release files

2.0.11

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page