pcpartpicker
v2.2.2
这是 pcpartpicker.com 网站的非官方 Python 3.7+ API。它是使用异步请求编写的,以实现高效的数据检索。该软件包目前处于稳定测试阶段。
通过 pip 可以轻松完成包检索和安装。
pip install pcpartpicker
为了使用该 API,只需从 pcpartpicker 包中导入 API 即可。
from pcpartpicker import API
然后,您可以实例化 API 类并使用它来发出请求。
api = API ()
cpu_data = api . retrieve ( "cpu" )
all_data = api . retrieve_all ()
api.retrieve()
和api.retrieve_all()
方法都返回一个PartData
实例,其中包含时间戳和to_json()
方法。
可以通过以下方式获取支持的部件列表:
api = API ()
print ( api . supported_parts )
>> > { 'wireless-network-card' , 'case-fan' , 'cpu' , 'cpu-cooler' , 'headphones' , 'motherboard' , 'monitor' , 'internal-hard-drive' , 'external-hard-drive' , 'ups' , 'fan-controller' , 'case' , 'keyboard' , 'mouse' , 'wired-network-card' , 'sound-card' , 'video-card' , 'speakers' , 'optical-drive' , 'power-supply' , 'thermal-paste' , 'memory' }
还有许多方法可用于自定义 API 行为。例如,您可以更改区域并确定可以建立的并发异步连接的数量。
检索支持的 API 区域:
api = API ()
print ( api . supported_regions )
>> > { 'be' , 'us' , 'it' , 'uk' , 'ie' , 'nz' , 'de' , 'ca' , 'au' , 'fr' , 'se' , 'es' , 'in' }
检索当前选定的区域(默认为美国):
api = API ()
print ( api . region )
>> > us
创建具有不同默认区域的 API 对象:
api = API ( "de" )
print ( api . region )
>> > de
更改默认区域:
api = API ()
api . set_region ( "de" )
print ( api . region )
>> > de