binmao linbs
Project description
py脚手架
安装
python版本号: 3.10.12
pip安装: pip install binmao_libs
相关模块
orm
使用peewee
orm框架
代码样例:
from binmao_libs import db
from peewee import *
# 创建database实例
mysql_db = db.connect(config.mysql_connection)
# 创建orm对象(表访问对象)
class MetaMoment(Model):
"""动态实体类
"""
id = IntegerField(unique=True)
uid = CharField()
text = CharField()
category_id = IntegerField(column_name="categoryId")
created_at = DateTimeField(column_name="createdAt")
class Meta:
database = mysql_db
table_name = "moment__moment"
class MetaUserInfo(Model):
"""用户信息
"""
id = IntegerField(unique=True)
nickname = CharField()
class Meta:
database = mysql_db
table_name = "metacat__user_info"
# 表查询
cursor = MetaMoment.select().limit(10)
for record in cursor:
print(f"text: {record.text}")
# 设置特定返回字段(prject)
cursor = MetaMoment.select(MetaMoment.id.alias("_id")).limit(10)
for record in cursor:
print(f"_id: {record._id}")
# 返回使用函数
cursor = MetaMoment.select(fn.COUNT(MetaMoment.id))
print(f"总数: {next(iter(cursor))}")
# 带游标查询
# 偏移10条数据,返回后续5条
cursor = MetaMoment.select().offset(10).limit(5)
for record in cursor:
print(f"id: {record.id}")
# 简单的联合查询
# 注意使用.dicts方法,将返回结果字典化
cursor = MetaMoment.select(MetaUserInfo.nickname).join(MetaUserInfo, on=(MetaUserInfo.id == MetaMoment.uid)).limit(1).dicts()
for record in cursor:
print(f"{record}")
# 更新操作
MetaMoment.update(text = "Hello World. 12345").where(MetaMoment.id == 1).execute()
# 插入
# MetaMoment.create(text = "Hello World. 12345").execute()
参考:
http服务
http服务包含对以下框架的封装:
- Flask http服务框架
- Flasgger swagger服务框架
- prometheus_flask_exporter 发布prometheus格式指标
举例:
from binmao_libs import https
from flask import request
# post请求
@https.app.post("/hello")
def hello():
"""hello
---
parameters:
- name: body
in: body
required: true
schema:
required:
- name
properties:
name:
type: string
description: name.
default: "csj"
response:
200:
description: 成功返回
examples:
{"state": "0", "msg": "success"}
"""
name = request.json["name"]
return json.dumps({"state": "0", "msg": "success", "data": {"name": name}})
https.run(application_name="binmaolibs")
参考:
oss服务
oss服务封装了七牛云存储对象的接口
使用举例
import base_test
import qiniu
from binmao_libs.oss import OssClient
# 构建oss_client
bucket_name = ''
oss_gateway = ""
access_key = ""
secret_key = ""
oss_client = OssClient(access_key, secret_key, bucket_name)
localfile = r"d:\BaiduSyncdisk\DatasetId_1864493_1687253829.zip"
key = "models/demo/1.png"
progress_handler = lambda progress: print(f"progress: {progress}")
oss_client.upload(localfile, key, progress_handler = progress_handler)
url = oss_gateway + "/" + key
print(url)
模型文件上传/下载服务
提供中心化管理模型方案,为公司内部模型共享提供便利
binmao-libs.yaml
项目目录中引入binmao-libs.yaml配置
model:
ftp:
host: "192.168.9.19"
usr: "wallan"
pwd: "wallan1702"
上传模型文件
from binmao_libs.model import download_model, upload_model
import logging
import os
models_dir = os.path.realpath(os.path.join(os.path.pardir, "models"))
logging.basicConfig(level="DEBUG")
download_model("rmbg", models_dir)
download_model("ViT-B-32", models_dir)
download_model("ViT-H-14", models_dir)
下载模型文件
from binmao_libs.model import download_model, upload_model
import logging
import os
models_dir = os.path.realpath(os.path.join(os.path.pardir, "models"))
logging.basicConfig(level="DEBUG")
upload_model(os.path.join(models_dir, "rmbg"), "rmbg")
upload_model(os.path.join(models_dir, "ViT-B-32"), "ViT-B-32")
upload_model(os.path.join(models_dir, "ViT-H-14"), "ViT-H-14")
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
binmao_libs_quart-0.0.1.tar.gz
(10.1 kB
view details)
Built Distribution
File details
Details for the file binmao_libs_quart-0.0.1.tar.gz
.
File metadata
- Download URL: binmao_libs_quart-0.0.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8f6f80aded0e363f47ade79ea227380094d2d816476b93a327e8f5313789fcb |
|
MD5 | 61afba8be18173e64c35484aa1d3776f |
|
BLAKE2b-256 | 4bee836dcbc9f671c7ac95be802ae9903c64325e34eeddb726e0256643d8d97e |
File details
Details for the file binmao_libs_quart-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: binmao_libs_quart-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0068a285fc323c473adeb12354724b1bbfc244ce7e5d8c9b316c8335109078fe |
|
MD5 | a7b0c477f396457086751552b2aaab9d |
|
BLAKE2b-256 | 08b382ed6216099ecabb4ea7799f813cbf9e48e15a5772c52c0b20d968d7d24a |