Skip to main content

用于调用 H API 的工具和组件。

项目描述

h-api

用于调用 H API 的工具和组件。

这个包可能对你没用

除非你为 Hypothesis 工作,否则这个包对你不会很有用。随意戳一下,但如果它没有多大意义,请不要感到惊讶。

目前你不仅不应该使用这个包,我们的身份验证也会阻止它。

用法

为批量 API 调用构建 NDJSON:

from h_api.enums import ViewType

from h_api.bulk_api import CommandBuilder, BulkAPI, Executor

nd_json = BulkAPI.to_string([
    # It's your job to put the right commands here. 
    # This also accepts a generator

    CommandBuilder.configure(
        effective_user="acct:example@lms.hypothes.is", 
        total_instructions=4, 
        view=ViewType.BASIC),

    CommandBuilder.user.upsert({
        "username": "username",
        "authority": "authority",
        "display_name": "display_name",
        "identities": [{
            "provider": "provider",
            "provider_unique_id": "provider_unique_id"
        }],
    }, "user_ref"),

    CommandBuilder.group.upsert({
        "name": "name",
        "authority": "authority",
        "authority_provided_id": "authority_provided_id"
    }, "group_ref"),
    
    # These references here match those we assigned to the objects above
    CommandBuilder.group_membership.create("user_ref", "group_ref")
])

# It's now your job to send this off to H

接受和处理像上面这样的 NDJSON 请求:

class MyExectutor(Executor):
    def execute_batch(self, command_type, data_type, default_config, batch):
        """Implement your insertion logic here and return Report Objects"""
        
rows = BulkAPI.from_byte_stream(http_streaming_body, executor=MyExectutor())

if rows:
    # Turn each row into JSON and return to your caller
    # You have to do this

设置你的 h-api 开发环境

首先你需要安装:

  • 吉特。在 Ubuntu 上:sudo apt install git,在 macOS 上:brew install git
  • GNU 使. 这可能已经安装,运行make --version检查。
  • pyenv。按照 pyenv 的 README 中的说明进行安装。Homebrew方法在 macOS 上效果最好。Basic GitHub Checkout方法在Ubuntu 上效果最好。你不需要设置 pyenv 的 shell 集成(“shims”),你可以 在没有 shims 的情况下使用 pyenv

然后设置您的开发环境:

git clone https://github.com/hypothesis/h-api.git
cd h_api
make help

发布项目的新版本

  1. 首先,要让 PyPI 发布工作,您需要访问: https ://github.com/organizations/hypothesis/settings/secrets/actions/PYPI_TOKEN 并将 h-api 添加到PYPI_TOKEN密钥的选定存储库中。

  2. 现在 h-api 项目可以访问PYPI_TOKEN密钥,您可以通过创建一个新的 GitHub release来发布一个新版本。发布新的 GitHub 版本将自动触发 GitHub Actions 工作流程 ,该工作流程将构建新版本的 Python 包并将其上传到 https://pypi.org/project/h-api

更改项目的 Python 版本

要更改项目使用的 Python 版本:

  1. 更改 cookiecutter.json文件中的 Python 版本。例如:

    "python_versions": "3.10.4, 3.9.12",
    
  2. 重新运行 cookiecutter 模板:

    make template
    
  3. 将所有内容提交到 git 并发送拉取请求

更改项目的 Python 依赖项

要更改setup.cfg文件中的生产依赖项:

  1. 更改.cookiecutter/includes/setuptools/install_requires文件中的依赖项。如果此文件尚不存在,请创建它并向其添加一些依赖项。例如:

    pyramid
    sqlalchemy
    celery
    
  2. 重新运行 cookiecutter 模板:

    make template
    
  3. 将所有内容提交到 git 并发送拉取请求

要更改项目的格式、linting 和测试依赖项:

  1. 更改.cookiecutter/includes/tox/deps文件中的依赖项。如果此文件尚不存在,请创建它并向其添加一些依赖项。使用 tox 的因子条件设置 来限制每个依赖项使用的环境。例如:

    lint: flake8,
    format: autopep8,
    lint,tests: pytest-faker,
    
  2. 重新运行 cookiecutter 模板:

    make template
    
  3. 将所有内容提交到 git 并发送拉取请求

项目详情


下载文件

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

源分布

h-api-1.0.2.tar.gz (71.8 kB 查看哈希

已上传 source

内置分布

h_api-1.0.2-py3-none-any.whl (30.1 kB 查看哈希

已上传 py3