Skip to main content

binmao linbs

Project description

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 = 'tpulse-assets'
oss_gateway = "https://assetsqiniu.ruixi-sh.com"
access_key = "jTp01Oa0dw2eLrmZP6MpIAPaHs2hQNpVct5L1QEy"
secret_key = "FNjvkqBP53JgU6KkFC_i_SoR7YrLtHmslHv231dk"
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)

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

binmao_libs-1.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

binmao_libs-1.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file binmao_libs-1.1.1.tar.gz.

File metadata

  • Download URL: binmao_libs-1.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for binmao_libs-1.1.1.tar.gz
Algorithm Hash digest
SHA256 9eb1692c4be6379a5b9656820e39635e5eb524d670ac09da145ba2a74ead217f
MD5 31156bfe1f620beea660c050f115078d
BLAKE2b-256 2938428796cc6f259949a9fe3fe78e2f3f16924728a1b837af37208df422f4ba

See more details on using hashes here.

File details

Details for the file binmao_libs-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: binmao_libs-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for binmao_libs-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8947a797b1e2ab9ae9bedd8ae446a6e1d83bcced17a35a9e3a97d2d7eb695245
MD5 250c834d0bba9d0502a875eb5f801cff
BLAKE2b-256 9dcdb1e6e2e29056dc76b262606c84abcd77a83880e0d2ec92d56050e9a29640

See more details on using hashes here.

Supported by

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