pdm install
These are equivalent (given the main.py code)
UVICORN_ROOT_PATH=/api/ pdm run uvicorn main:app
FASTAPI_ROOT_PATH=/api/ pdm run uvicorn main:app
| ## Build angular site | |
| - name: build | |
| pull: if-not-exists | |
| image: node:16.18.1-alpine | |
| when: | |
| branch: | |
| - master | |
| event: | |
| - push | |
| commands: |
每个 Python 程序员可能都会遇到这样的场景:你写了一个 Python 程序,可能是一个简单的、包含单个文件的 、只使用了标准库的 Python 脚本,抑或是一个庞大的、包含多个模块的、甚至引用了大量的第三方库的复杂 Python 应用,如何将他们送到目标用户手中,让他们能很顺利地使用起来呢?
一种方案就是写一个详尽的文档,连带着你的程序一起发送给用户。文档中要说明,目标用户如何在自己机器上安装 Python 环境及依赖的包,如何对程序进行配置,等等。但倘若你的目标用户没用过 Python 甚至不懂编程,此种方案执行起来便困难重重。
另一种方案,就是将 Python 程序“打包”成可执行程序(.exe),只要目标用户具备基本的电脑操作技能,便能很容易地将程序运行起来。
在 Windows 平台上,将 Python 程序“打包”为可执行程序(.exe)的方案很多,我尝试过的方案有如下几种:
| #!/usr/bin/env bash | |
| # Use this script to test if a given TCP host/port are available | |
| WAITFORIT_cmdname=${0##*/} | |
| echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } | |
| usage() | |
| { | |
| cat << USAGE >&2 |
| # -*- coding: utf-8 -*- | |
| # forwards the calls to http://localhost:8000/https://google.com to https://google.com - copying the headers, query strings, etc | |
| from fastapi import FastAPI, Request, Response | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import requests | |
| app = FastAPI() |
| This is Python's http.server that has been bundled to an .exe using PyInstaller. You can use it as a local web server for testing. | |
| Run the local server | |
| 1. Copy the server.exe into the folder you want to serve and then double click it to start the local server. | |
| 2. A window will pop up letting you know the server is running on port 8000. | |
| 3. Open http://localhost:8000/ in your web browser. | |
| 4. When you are done, simply close the server.exe window to stop the local server. | |
| If you have another service running on port 8000, you can run on a different port like so: | |
| 1. Open Command Prompt |
A Docker compose to learn about MongoDB noSQL database.
With MongoExpress webUI (written with Node.js and express).
Docs:
| from tinydb import TinyDB | |
| # Disk storage | |
| db = TinyDB('data.json') | |
| # Memory storage | |
| from tinydb.storages import MemoryStorage, Storage | |
| db = TinyDB(storage=MemoryStorage) |
| --- | |
| kind: pipeline | |
| type: docker | |
| name: linux-amd64 | |
| trigger: | |
| branch: | |
| - myapp | |
| event: |