# 阿里云日志服务SLS python SDK和CLI

阿里云的SLS日志服务提供了Python SDK，并提供了aliyun-sls-cli客户端，非常容易安装使用。

SLS的命令行工具(Command Line Interface - CLI) 支持几乎所有操作，日志查询支持完整性检查与自动分页、支持多账户与跨域复制。

## 安装

* 我使用Python virtualenv 来运行python程序，使用以下命令安装日志服务器CLI

```bash
pip3 install aliyun-log-python-sdk aliyun-log-cli -U --no-cache
```

对于需要大量下载和传输数据的命令，例如 `copy_data` `pull_log_dump` ，建议使用 `pypy` 或 `pypy3` 来安装，可以获得更好的性能。

* 创建 `aliyunlog` 文件，并设置可执行，放到PATH目录下:

```python
#!/Users/huatai/venv3/bin/python
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('aliyun-log-cli', 'console_scripts', 'aliyunlog')()
    )
```

## 参考

* [Aliyun Log Service CLI 用户手册](https://aliyun-log-cli.readthedocs.io/en/latest/README_CN.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/develop/python/startup/install_aliyun_sls_python_sdk_and_cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
