py脚手架
安装
python版本号: 3.10.12
pip安装: pip install binmao_libs
相关模块
orm
使用peeweeorm框架
代码样例:
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
upload_model(r"/Users/chishijie/Documents/bingmao/python/binmao-libs/dist", "binmao-libs")
下载模型文件
from binmao_libs.model import download_model, upload_model
download_model("binmao-libs", r"/Users/chishijie/Documents/bingmao/python/binmao-libs/tmp")
Metadata
Release files for binmao-libs 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| binmao_libs-1.2.1.tar.gz | 9.9 kB | Without provenance | Details for binmao_libs-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| binmao_libs-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for binmao_libs-1.2.1-py3-none-any.whl |
Total release size: 19.1 kB
Release files / binmao_libs-1.2.1.tar.gz
| Download URL | binmao_libs-1.2.1.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8cc0dea76681f76de0ceaf09de56f1815c366d5a691c9930d570a493c2717a13
|
|
BLAKE2b-256 checksum How to use checksums |
bd30d69c64d9d615023e135e0e69e082980ecd393f6c7b3c367e88f9d6118190
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / binmao_libs-1.2.1-py3-none-any.whl
| Download URL | binmao_libs-1.2.1-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31ff17f238f8a336a78b178020bd8b28a91a8b401fb1e4be4405f43221305a7f
|
|
BLAKE2b-256 checksum How to use checksums |
16da6afebe5fab176b6f41f90739a6e90d3ecd483d2e1fa248d27642ed8dc56e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for binmao-libs 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.