跳转到主要内容

使用Python requests查询neuromorpho.org数据库

项目描述

neuromorpho-api

使用requests查询neuromorpho.org数据库。

As of May 2024, the SSL key for neuromorpho.org has been updated, and the
workaround packaged here is no longer necessary!
The [requests](https://pypi.ac.cn/project/requests/) package can now be used
directly with the neuromorpho.org API.
This project will be archived, though the documentation will remain live and
updated to demonstrate programmatic access of neuromorpho data.

快速入门

>>> import requests

>>> neuron_endpoint = "https://neuromorpho.org/api/neuron/"
>>> resp = requests.get(neuron_endpoint + "fields")
>>> resp.json()
{'Neuron Fields': ['neuron_id',
  'neuron_name',
  'archive',
  'age_scale',
  'gender',
  ...

请参阅教程以获取更详细的示例,包括按属性模式匹配选择神经元下载SWC迹线


这个包是什么?

neuromorpho-api包提供了一个带有自定义SSLContextrequests.Session实例,用于与neuromorpho.org交互。

为什么不能直接使用requests

注意:自05-24起不应再是问题

您可能会看到以下内容

>>> import requests
>>> requests.get("https://neuromorpho.org/api/neuron/id/1")
Traceback (most recent call last)
   ...
SSLError: HTTPSConnectionPool(host='neuromorpho.org', port=443): Max retries exceeded with url: /api/neuron/id/1 (Caused by SSLError(SSLError(1, '[SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1006)')))

这似乎是neuromorpho.org提供的密钥与默认Python SSL加密方式不兼容。此包使用Robin De Schepper在Stack Overflow上发布的解决方案解决这个问题。将来某个时候,neuromorpho证书可能会(希望)更新,届时此包将被存档。

未来兼容性

此包提供的requestor旨在作为解决当前neuromorpho.org DH密钥问题的临时解决方案。如果neuromorpho.org证书更新,则不再需要带有自定义SSLContext的requestor,用户可以直接使用requests。因此,建议以下导入别名

from neuromorpho-api import requestor as requests

更新证书后,以上内容可以更改为

import requests

所有依赖于 requests.get 的代码应继续按预期工作。

项目详情


下载文件

下载适用于您平台文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源代码分发

neuromorpho_api-0.2.tar.gz (4.5 kB 查看哈希值)

上传时间 源代码

构建分发

neuromorpho_api-0.2-py3-none-any.whl (5.1 kB 查看哈希值)

上传时间 Python 3