跳转到主要内容

访问尼罗河API的客户端库

项目描述

这是与尼罗河交互的Python SDK。

安装

尼罗河Python SDK可在PyPI上找到,可以通过以下方式安装:

pip install nile-api

(在适当的虚拟环境中)。

使用方法

SDK的使用示例可以在Nile的示例仓库中找到,位于包含-python的目录中。

基本示例

import os

from nile_api import AuthenticatedClient
from nile_api.api.users import create_user, list_users
from nile_api.models.create_user_request import CreateUserRequest

# Create an authenticated client with a workspace auth token
client = AuthenticatedClient(base_url='https://prod.thenile.dev', token=os.environ.get("NILE_WS_TOKEN"))

# Create a user
user = create_user.sync(
            workspace=os.environ.get("NILE_WORKSPACE"),
            client=client,
            json_body=CreateUserRequest(email="anon@anon.com", password="secret"),
        )

# Log created user to console
print(user.email);

# List all users in the workspace
users = list_users.sync(client=client, workspace=os.environ.get("NILE_WORKSPACE"))
for user in users:
    print(f"User {user.email!r} exists")

开发

以下命令通常使用nox(在某种意义上是一种基于Python、以测试为中心的make)。

您可以通过遵循其针对您操作系统的安装说明来安装它,例如在macOS上,只需运行

brew install nox

通过openapi-python-client来重新生成(更新)客户端。

要这样做,请运行

nox -s regenerate

您将想要测试结果。首先,验证生成的客户端具有预期的结构(包和模块)

要这样做,请运行

nox -s tests

然后您将想要进行快速测试,并确保客户端确实可以针对Nile工作。目前我们通过运行https://github.com/TheNileDev/examples/tree/main/quickstart-python示例来做到这一点。在运行之前,您需要确保运行示例将使用本地客户端而不是已安装的客户端。

从本地nile-py仓库目录运行

export PYTHONPATH=`pwd`:$PYTHONPATH
venv/bin/python -c "import nile_api; print(str(nile_api.__path__))"
cd ../examples/quickstart-python
./venv/bin/python src/all.py

我们在requirements文件中固定了此生成器的版本。要更新将使用的生成器版本,请运行

nox -s update_openapi_requirements

这将重新生成openapi-generator-requirements.txt文件,您应该将其提交。

项目详情


下载文件

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

源代码分发

nile_api-0.2.8.tar.gz (44.7 kB 查看散列)

上传时间 源代码

构建分发

nile_api-0.2.8-py3-none-any.whl (125.2 kB 查看散列)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面