有现代化设施的图书馆,以提高开发效率
modutils的Python项目详细描述
Modutils公司
Modern python3 utilities
A collection of classes and functions
最常见的公用事业
艾奥洛普
此函数提供了一种使用另一个已定义函数来提供异步功能的简单方法。 命名参数应在参数列表内的单个字典中提供。在
^{pr2}$aiobulk
aiobulk是一个装饰器,用于向现有函数添加bulk属性。这个装饰器利用aioloop实现异步功能。在
importrequestsfrommodutils.decoratorsimportaiobulk# example w/o named arguments@aiobulkdefadd(x:int,y:int)->int:returnx+yargs=[[x,y]forxinrange(0,5)foryinrange(5,10)]list_of_returns=add.bulk(args)# example w/ named arguments@aiobulkdefget_url(url,params:dict=None):returnrequests.get(url,params=params)args=[['https://www.google.com',{'params':{'q':'Why is the sky blue?'}}],['https://www.github.com']]list_of_returns=get_url.bulk(args)
基本会话
这个类是一个修改过的请求会话类,它支持每个请求的日志记录,并将持续尝试解析具有错误状态代码的请求。在
frommodutils.httpimportBaseSession
BaseAsyncSession
这个类是用BaseSession和aiobulk构建的,为每个请求函数提供一个bulk属性:get、put、post、patch、head和delete
frommodutils.httpimportBaseAsyncSessionsession=BaseAsyncSession()args=[['https://www.google.com',{'params':{'q':'Why is the sky blue?'}}],['https://www.github.com']]list_of_returns=session.get.bulk(args)
电子邮件
Email类允许通过未经身份验证或已验证的会话发送电子邮件的简单方法
frommodutils.httpimportEmail
Urlscraper
urlscraper方法是搜索web页面以查找与给定模式匹配的内容的一种简单方法
frommodutils.httpimporturlscraper# this example will use a regex pattern to find all the sha256 hashes in a given blog# note: the blog is fake and will need to be replaced for examplesha256hashes=urlscraper('https://fakeblogsite.com','[A-Fa-f0-9]{64}',regex=True)
回声
echo是一种奇特的打印,它允许您轻松地以最漂亮的形式打印对象,添加颜色,并刷新当前行。在
frommodutilsimportechoecho({'hello':'world'},color='red')
Documentation
在modutils.aio模式在
在modutils.aio模式定义一个名为Eventloop的新类型。此类型是在运行时创建的,用于按操作系统指定类型。在
aioloop(function: Callable, args_list: List[List], loop: Eventloop = None, max_async_pool: int = 16, max_futures: int = 100000, disable_progress_bar: bool = False, progress_bar_color: str = 'green_3a', progress_bar_format: str = None) -> list
创建新的aioloop,运行并返回结果
:param fn {Callable}: function to map to arguments
:param args_list {List[List]}: list of arguments to send to function
:param loop {Eventloop}: a pre-defined asyncio loop
:param max_async_pool {int}: max async pool, this will define the number of processes to run at once
:param max_futures {int}: max futures, this will define the number of processes to setup and execute at once.
If there is a lot of arguments and futures is very large, can cause memory issues.
:param disable_progress_bar {bool}: disable progress bar from printing
:param progress_bar_color {str}: color of progress bar; default: green
:param progress_bar_format {str}: format for progress bar output; default: None
:return list of results
在modutils.decorators在
aiobulk.__init__(self, function: Callable)
初始化aiobulk 被修饰的函数将接收批量调用的新属性
:param function: function being decorated
aiobulk.bulk(self, args_list: List[list], loop: <function NewType.<locals>.new_type at 0x0000021B97E921F0> = None, max_async_pool: int = 16, max_futures: int = 100000, disable_progress_bar: bool = False, progress_bar_color: str = 'green_3a', progress_bar_format: str = None) -> list
向给定函数添加名为“bulk”的方法
:param function {Callable}: function to map to arguments
:param loop {Eventloop}: a pre-defined asyncio loop
:param max_async_pool {int}: max async pool, this will define the number of processes to run at once
:param max_futures {int}: max futures, this will define the number of processes to setup and execute at once.
If there is a lot of arguments and futures is very large, can cause memory issues.
:param disable_progress_bar {bool}: disable progress bar from printing
:param progress_bar_color {str}: color of progress bar; default: green
:param progress_bar_format {str}: format for progress bar output; default: None
:return list of results
在modutils.http在
urlscraper(url: str, pattern: str, regex: bool = False) -> list
urlscraper是一种基于给定字符串模式从url中获取信息的简单方法
:param url: the url to run pattern against
:param pattern: the string representation of the pattern
:param regex: flag for using a pattern as regex or string compare
:return: list of strings that matched or contained pattern
在modutils.http.BaseAsyncSession(自身,*args,**kwargs)
BaseAyncSession用于需要能够发出异步请求的会话
BaseAsyncSession.__init__(self, *args, **kwargs)
初始化BaseAyncSession
:param args: list of args
:param kwargs: dict of named args
在modutils.http.BaseSession(self,max_retries:int=3,pool_connections:int=16,pool_maxsize:int=16,解析状态代码:list=None,verbose:bool=False,auth:tuple=None)
BaseSession,它将记录请求和持久化请求,以尝试解析所需的状态代码
BaseSession.__init__(self, max_retries: int = 3, pool_connections: int = 16, pool_maxsize: int = 16, resolve_status_codes: list = None, verbose: bool = False, auth: tuple = None)
初始化BaseSession
:param max_retries: maximum amount of retries if non resolved status code found
:param pool_connections: number of pool connection; default 16
:param pool_maxsize: max number of connections in pool; default 16
:param resolve_status_codes: extra status codes to resolve; default None
:param verbose: more verbose logging output if response fails; default False
:param auth: basic auth username and password tuple; default None
在modutils.http.电子邮件(自身,smtp服务器,smtp端口,发件人地址:str=None,所需身份验证:bool=False,auth_用户名:str=None,auth_密码:str=None)
类来轻松发送电子邮件
Email.__init__(self, smtp_server, smtp_port, from_address: str = None, authentication_required: bool = False, auth_username: str = None, auth_password: str = None)
创建新的电子邮件会话
Email.send(self, subject: str, body: str, to_address_list: list, cc_address_list: list = None, from_address: str = None, encoding: str = 'html', logo_images: list = None, file_attachments: list = None) -> dict
:param subject: Subject string for email, required
:param body: Message content for email, required
:param to_address_list: addresses to send email to, required
:param cc_address_list: addresses to cc on email, default: None
:param from_address: address to send email from, default: None, will use self.from_address if one was given
:param encoding: encoding for body, default: html
:param logo_images: list of paths to images to use for logos, default: None
:param file_attachments: list of paths to attachments for email, default: None
:return: dict
modutils公司
echo(content: Any, list_delimiter: str = '\n', indent: int = 4, color: str = None, flush: bool = False) -> None
回显-自动漂亮打印或解析为可打印对象
:param content: the object to print
:param list_delimiter: delimiter to join list; default:
:param indent: indent space count; default: 4
:param color: change color of text; default: None
:param flush: flush will make the current line be overwritten; default: False
:return: None
globpath(filepath: str) -> str
将文件路径转换为全局路径,['/'|'']转换为'.'
filepath {str} -- filepath to glob
return {str} -- new globpath
has_package(name: str, version: Union[str, int, float] = None) -> bool
检查当前环境是否有包
name {str} -- name of package to check
version {Union[str, int, float]} -- OPTIONAL, will append version for a specific version check of package
return {bool} -- True if package was found and False if not
import_from(globpath: str, name: str) -> Union[object, NoneType]
导入模块并返回g的实例依文函数名
globpath {str} -- the filepath in glob format
name {str} -- the method name to import
return {Union[object, None]} -- method attribute of import
install_package(name: str, force: bool = False, extra_index: str = None, trusted_host: str = None) -> Tuple[str, str]
使用当前环境中的子进程安装pip3包
name {str} -- name of package to install
force {bool} -- force newest edition
extra_index {str} -- extra url to index in package manager
trusted_host {str} -- extra url where package is hosted
return {tuple} -- return the output, and error of subprocess run
list_packages() -> list
列出环境中当前的pip3包
^{pr21}$nget(dictionary: dict, keys: Iterable, default: Any = None) -> Any
nget-nested get call通过一个调用轻松检索嵌套信息并设置默认值 前任。 nget(dict,['key1','key2',…],默认) nget(dict,('key1','key2',…),默认)
nget use an iterable of keys to retrieve nested information and can set a default if a key is not found
在modutils.stdutils公司在
scroll(content: list, sleep_timer=1, list_delimiter: str = '\n', indent: int = 4, color: str = None) -> None
使用echo和delay在同一行上滚动文本
:param content: the object to print
:param list_delimiter: delimiter to join list; default:
:param indent: indent space count; default: 4
:param color: change color of text; default: None
:return: None
update_package(name: str, extra_index: str = None, trusted_host: str = None) -> Tuple[str, str]
按名称更新pip3包,利用force=True的install\u包
name {str} -- name of package to install
extra_index {str} -- extra url to index in package manager
trusted_host {str} -- extra url where package is hosted
return {tuple} -- return the output, and error of subprocess run
在modutils.sha256型(自身,值)
sha256型
- 项目
标签: