

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 读取 Neptune 流数据
<a name="streams-using-reading"></a>

以下示例说明如何从属性图流端点读取记录。你可以使用 Amazon CLI、适用于 Python 的 Amazon SDK (Boto3)、或。**awscurl** **curl**

------
#### [ Amazon CLI ]

```
aws neptunedata get-propertygraph-stream \
  --endpoint-url https://{{your-neptune-endpoint}}:{{port}} \
  --iterator-type TRIM_HORIZON \
  --limit 10
```

要从流中的特定位置读取，请使用`--commit-num`和`--iterator-type`参数：

```
aws neptunedata get-propertygraph-stream \
  --endpoint-url https://{{your-neptune-endpoint}}:{{port}} \
  --limit 10 \
  --commit-num 1 \
  --iterator-type AT_SEQUENCE_NUMBER
```

有关更多信息，请参阅《命令参考》中的 [get-propertygraph-stream](https://docs.amazonaws.cn/cli/latest/reference/neptunedata/get-propertygraph-stream.html)。 Amazon CLI 

------
#### [ SDK (Python) ]

```
import boto3
import json
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    region_name='{{us-east-1}}',
    endpoint_url='https://{{your-neptune-endpoint}}:{{port}}',
    config=Config(read_timeout=65)
)

response = client.get_propertygraph_stream(
    limit=10,
    iteratorType='TRIM_HORIZON'
)

print(json.dumps(response['records'], indent=2, default=str))
```

要对直播进行分页，请在响应`opNum``lastEventId`中使用`commitNum`和：

```
last_event = response['lastEventId']
next_response = client.get_propertygraph_stream(
    limit=10,
    commitNum=last_event['commitNum'],
    opNum=last_event['opNum'],
    iteratorType='AFTER_SEQUENCE_NUMBER'
)
```

------
#### [ awscurl ]

```
awscurl https://{{your-neptune-endpoint}}:{{port}}/propertygraph/stream?limit=10 \
  --region {{us-east-1}} \
  --service neptune-db
```

**注意**  
此示例假设您的 Amazon 证书是在您的环境中配置的。{{us-east-1}}替换为 Neptune 集群的区域。

有关**awscurl**与 IAM 身份验证配合使用的更多信息，请参阅[使用带有临时证书的 `awscurl` 安全地连接到启用 IAM 身份验证的数据库集群](iam-auth-connect-command-line.md#iam-auth-connect-awscurl)。

------
#### [ curl ]

```
curl https://{{your-neptune-endpoint}}:{{port}}/propertygraph/stream?limit=10
```

**注意**  
只有在您的 Neptune 集群上禁用 IAM 身份验证时，**curl**不使用 Sigv4 签名才能使用。如果启用了 IAM 身份验证，请 Amazon CLI 改用**awscurl**或。

------

对于 SPARQL 图形，请在前面的示例`/sparql/stream`中`/propertygraph/stream`替换为。使用 Amazon CLI 或 SDK 时，请`client.get_sparql_stream()`改用`get-sparql-stream`或。

## 在图表笔记本中查看流数据
<a name="streams-using-notebook"></a>

如果您使用 [Neptune 图形笔记本](graph-notebooks.md)，则`%stream_viewer`线条魔法提供了一个可视化界面，无需编写代码即可以交互方式浏览直播记录。在笔记本单元中运行以下命令：

```
%stream_viewer
```

您可以选择指定查询语言和页面大小：

```
%stream_viewer sparql --limit 20
```

有关更多信息，请参阅 [`%stream_viewer` 行魔术命令](notebooks-magics.md#notebooks-line-magics-stream-viewer)。

**注意**  
只有引擎版本 1.0.5.1 及更早版本才完全支持该`%stream_viewer`魔法。