Skip to main content

base_common_lib

常用的基础通用Lib集合

快速入门

安装

pip install baselib

【模块】log

  1. 创建日志文件
from baselib.log import file_logger
# 生成 logger 对象,默认自定义了日期格式,以及按天做日志分割
logger = file_logger("文件路径+名称")

logger.info("info msg")
logger.debug("debug msg")

【模块】json

  1. json文件读写,更新
from baselib.json import JsonFile

# 获取json格式文件,当读取异常时返回空的dict
data = JsonFile.read("文件路径+名称")

# 写入json格式文件
JsonFile.write("文件路径+名称", data)

# 直接更新文件,不需要先调用read
JsonFile.update("文件路径+名称", {"1": 2})

【模块】time

  1. 日期段计算 period (简化datetime的调用)
from baselib.time import Period
# 获取近一个小时的起止时间
start_time, end_time = Period.get_recent_hour(1)

# 获取当前时间
now = Period.now()

# 将当前时间转换格式
now_str = Period.formate_datetime(now)

【模块】system

  1. 执行系统命令,并获取返回结果,可以设置是否后台执行,超时时间
from baselib import system

# 执行命令行命令
system.run_cmd("pwd")

# 可以设置是否后台执行,超时时间等
system.run_cmd("ping 8.8.8.8", deamon=False, timeout=2)
  1. 创建目录(多级目录,安全创建),不存在时创建,存在时跳过,不会报错
from baselib import system

system.mkdirs("/xxx/yyy/zzz")
  1. 检查文件是否存在
from baselib import system
system.check_file("xxxx/xxx") 
# 返回检查结果: File, Directory, NotExists

【模块】qywx

  1. 发送企业微信机器人消息
from baselib.qywx import QyWechat
key = "xxxxxxx"  # robot key
robot = QyWechat(key=key, is_ssl=True, debug=True)
robot.send_markdown(
    msg="# Hello world\n> msg from robot",
    page_type=robot.EnumPageType.SPLIT_BY_LINES
)

Metadata

Release files for baselib 1.1.0.2

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

Source distribution (sdist)

Source distribution for baselib 1.1.0.2
File Size Uploaded Provenance
baselib-1.1.0.2.tar.gz 31.2 kB Without provenance Details

Release files / baselib-1.1.0.2.tar.gz

Download URL baselib-1.1.0.2.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
71fe5b2e0a6e3f88111ff0db37835024a90c2bbece7f3d3d4faf7687f5b330a8
BLAKE2b-256 checksum
How to use checksums
50a6bd37c880b39d9ffab7cab3768989e31565d3ccc449b1187abcf3b661dee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.11

Security for baselib 1.1.0.2

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.

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