Python: 进阶系列之一:常用第三方库

本文介绍了如何使用Django框架处理客户端上传的文件,并列举了一系列常用的Python库及其用途,涉及网络请求、图像处理、数据科学等领域。

爬虫类

  • requests:访问网络资源,使用,比内置的urllib更好用
"""
    这是一个以django框架的后端API,当客户端上传文件到后端时,后端API的处理逻辑
    如果想要看前端如何提交一个文件,请参考链接:https://blog.youkuaiyun.com/wucong60/article/details/81289227
"""

from django.http import HttpResponse, HttpRequest, JsonResponse
from io

def post_cz_file(request: HttpRequest):
    file_obj = request.FILES.get('file')
    file_bytes = file_obj.read() # better to use chunk if file is big
    # print('s', type(s))
    # print('file_obj', file_obj)
    # print(type(file_obj))
    # print('chunks', file_obj.chunks())

    params = {
        'access_token': '',
        'file_id': '',
        'index': 0,
    }

    files = {
        'inputStream': ('file', io.BytesIO(file_bytes), 'image/png')
    }

    # files = {'inputStream': (open('b.png', 'rb'))}
    try:
        r = requests.post(url, params=params, files=files)
        if r.status_code == 200:
            return r.json()
        else:
            print(r.json())
            raise Exception("请求失败,未知错误, code:%s" % r.status_code)
    except Exception as ex:
        print(ex)
        raise ex

    return JsonResponse(result)
  • lxml:可以使用xpath获取html元素的信息

PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了。PIL功能非常强大,但API却非常简单易用。安装命令pip install pillow

库名帮助文档
arrayhttps://docs.python.org/2.7/library/array.html
cmathhttps://docs.python.org/2.7/library/cmath.html
collectionshttps://docs.python.org/2.7/library/collections.html
copyhttps://docs.python.org/2.7/library/copy.html
datetimehttps://docs.python.org/2.7/library/datetime.html
dateutilhttps://pypi.python.org/pypi/dateutils/0.6.6
functoolshttps://docs.python.org/2.7/library/functools.html
heapqhttps://docs.python.org/2.7/library/heapq.html
itertoolshttps://docs.python.org/2.7/library/itertools.html
jsonhttps://docs.python.org/2.7/library/json.html
mathhttps://docs.python.org/2.7/library/math.html
operatorhttps://docs.python.org/2.7/library/operator.html
pytzhttps://pypi.python.org/pypi/pytz/2015.2
randomhttps://docs.python.org/2.7/library/random.html
rehttps://docs.python.org/2.7/library/re.html
stringinghttps://docs.python.org/2.7/library/stringing.html
timehttps://docs.python.org/2.7/library/time.html
xmlhttps://docs.python.org/2.7/library/xml.html
库名简单说明文档地址
ta-libTALib是一个处理金融数据和技术分析的开放代码库http://mrjbq7.github.io/ta-lib/
numpyNumPy系统是Python的一种开源的数值计算扩展。NumPy(Numeric Python)提供了许多高级的数值编程工具,如:矩阵数据类型、矢量处理,以及精密的运算库。专为进行严格的数字处理而产生http://www.numpy.org
scipySciPy是一款方便、易于使用、专为科学和工程设计的Python工具包。它包括统计,优化,整合,线性代数模块,傅里叶变换,信号和图像处理,常微分方程求解器等等http://www.scipy.org
pandasPython Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具。pandas提供了大量能使我们快速便捷地处理数据的函数和方法http://pandas.pydata.org
anyjson一个几乎可以把任何对象(anything)转换为序列化json的工具https://bitbucket.org/runeh/anyjson/src
graphviz一个绘图工具,可以根据dot脚本画出树形图https://graphviz.gitlab.io/about/
lasagnePyhton深度学习库http://lasagne.readthedocs.org/en/latest/
seaborn该模块是一个统计数据可视化库http://seaborn.pydata.org
requests网络访问模块http://docs.python-requests.org
pycryptoPython加密工具包https://www.dlitz.net/software/pycrypto/
beautifulsoup4python下很帅气的爬虫包https://www.crummy.com/software/BeautifulSoup
xlrd读取Excel的扩展工具https://xlrd.readthedocs.io/en/latest/
cvxoptcvxopt是一个最优化计算包,进行线性规划、二次规划、半正定规划等的计算http://cvxopt.org/
gensimgensim用于计算文本相似度,依赖NumPy和SciPy这两大Python科学计算工具包http://radimrehurek.com/gensim/tutorial.html
matplotlibmatplotlib可能是Python 2D绘图领域使用最广泛的库。它能让使用者很轻松地将数据图形化,并且提供多样化的输出格式http://matplotlib.org/mpl_toolkits/index.html
statsmodelsStatismodels是一个Python包,提供一些互补scipy统计计算的功能,包括描述性统计和统计模型估计和推断http://statsmodels.sourceforge.net
theanoPyhton深度学习库http://deeplearning.net/software/theano/
xlwt写入Excel文件的扩展工具https://xlwt.readthedocs.io/en/latest/
openpyxl一个python读写Excel 2010文件的库http://openpyxl.readthedocs.io/en/default/
quantLib-Python一个有名的金融计算库,能方便地用于计算许多金融模型和公式https://www.quantlib.org/
mysql-connector-pythonMySQL官方提供的驱动器https://dev.mysql.com/doc/dev/connector-python/8.0/
wxpy实现微信一些自动化功能https://github.com/youfou/wxpy

https://www.cnblogs.com/welhzh/p/5972107.html

 

numpy:核心数据组织 ndarray,常用统计函数

pandas:数据二维报表风格管理,index,columns, value

scipy:常用科学计算库:傅里叶变化,优化算法等

matplotlib:数据可视化基础包,提供基础绘图功能

seaborn:数据可视化高级包,提供数据统计分析专业函数以及绘图方法。

 

https://quant.pobo.net.cn/doc?name=api#%E9%99%84%E5%BD%95%E4%BA%8C-%E6%94%AF%E6%8C%81%E7%9A%84python%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93

创建WebApplication

Django:  功能全,推荐用这个

Flask: 适合用于微小型项目,6-7行代码就可以把API创建起来。

定时job应用

apscheduler

from apscheduler.schedulers.background import BackgroundScheduler

scheduler = BackgroundScheduler()

# 表示每天06点00分执行该程序 
scheduler.add_job(corn_service.execute, 'cron', hour=6, minute=00)

# 定时job存证:表示每隔5分执行该程序 
scheduler.add_job(china_jci_service.execute, 'interval', seconds=300)

加密(md5,sha1等)

hashlib

# md5加密
sign = hashlib.md5('something').hexdigest()


# sha1加密
sha1 = hashlib.sha1(file_bytes)
hash_value = sha1.hexdigest()

深拷贝与浅拷贝

import copy

数据库ORM框架: SQLAlchemy

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值