{"id":18881061,"url":"https://github.com/tylertemp/aliyun-log-sdk-python","last_synced_at":"2026-02-20T23:30:19.007Z","repository":{"id":86362582,"uuid":"66000275","full_name":"TylerTemp/aliyun-log-sdk-python","owner":"TylerTemp","description":"AliYun Log Service with a fix of \"headers value can not be int\" bug","archived":false,"fork":false,"pushed_at":"2016-08-18T14:26:23.000Z","size":101,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T03:26:13.956Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TylerTemp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-18T13:40:16.000Z","updated_at":"2016-08-18T14:26:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8382ea4-8fec-404b-b0bd-7fa985a52357","html_url":"https://github.com/TylerTemp/aliyun-log-sdk-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerTemp%2Faliyun-log-sdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerTemp%2Faliyun-log-sdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerTemp%2Faliyun-log-sdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerTemp%2Faliyun-log-sdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TylerTemp","download_url":"https://codeload.github.com/TylerTemp/aliyun-log-sdk-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239850445,"owners_count":19707348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T06:47:12.661Z","updated_at":"2026-02-20T23:30:18.948Z","avatar_url":"https://github.com/TylerTemp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# log service  Python sdk\r\npython sdk 是对所有log service提供的API的封装，通过该sdk，可以调用所有log service 开放的API: http://gitlab.alibaba-inc.com/sls/api_doc/\r\n\n## About this folk\n\nThis fork is from [AliYun Log Service](https://help.aliyun.com/document_detail/29077.html?spm=5176.doc29064.6.212.C1zQnw) with a fix of \"headers value can not be int\" bug.\n\nAlso, change the packages name to `aliyun_log`. This only effect\nhow `pip uninstall \u003cpackagename\u003e`. You can import as the way\nof the official source code.\n\nInstall by\n\n```\npip install git+https://github.com/TylerTemp/aliyun-log-sdk-python.git\n```\n\n## Code sample\r\n\r\n```\r\n\r\n#!/usr/bin/env python\r\n#encoding: utf-8\r\n\r\nimport time\r\n\r\nfrom aliyun.log.logexception import LogException\r\nfrom aliyun.log.logitem import LogItem\r\nfrom aliyun.log.logclient import LogClient\r\nfrom aliyun.log.getlogsrequest import GetLogsRequest\r\nfrom aliyun.log.putlogsrequest import PutLogsRequest\r\nfrom aliyun.log.listtopicsrequest import ListTopicsRequest\r\nfrom aliyun.log.listlogstoresrequest import ListLogstoresRequest\r\nfrom aliyun.log.gethistogramsrequest import GetHistogramsRequest\r\nfrom aliyun.log.index_config import *\r\nfrom aliyun.log.logtail_config_detail import *\r\nfrom aliyun.log.machine_group_detail import *\r\nfrom aliyun.log.acl_config import *\r\n\r\ndef sample_put_logs(client, project, logstore):\r\n    topic = 'TestTopic_2'\r\n    source = ''\r\n    contents = [\r\n        ('key_1', 'key_1'),\r\n        ('avg', '30')\r\n    ]\r\n    logitemList = [] # LogItem list\r\n    logItem = LogItem()\r\n    logItem.set_time(int(time.time()))\r\n    logItem.set_contents(contents)\r\n    for i in range(0, 1) :\n        logitemList.append(logItem)\r\n    request = PutLogsRequest(project, logstore, topic, source, logitemList)\r\n\n    response = client.put_logs(request)\r\n    response.log_print()\r\n\ndef sample_pull_logs(client, project, logstore) :\n    res = client.get_cursor(project, logstore, 0, (int)(time.time() - 60))\r\n    res.log_print()\r\n    cursor = res.get_cursor()\r\n\r\n    res = client.pull_logs(project, logstore, 0, cursor, 1)\r\n    res.log_print()\r\n\r\n\r\ndef sample_list_logstores(client, project):\r\n    request = ListLogstoresRequest(project)\r\n    response = client.list_logstores(request)\r\n    response.log_print()\r\n\n\r\ndef sample_list_topics(client, project, logstore):\r\n    request = ListTopicsRequest(project, logstore, \"\", 2)\r\n    response = client.list_topics(request)\r\n    response.log_print()\r\n\r\n\r\ndef sample_get_logs(client, project, logstore):\r\n    topic = 'TestTopic_2'\r\n    From = int(time.time())-3600\r\n    To = int(time.time())\r\n    request = GetLogsRequest(project, logstore, From, To, topic)\r\n    response = client.get_logs(request)\r\n    response.log_print()\r\n\r\n\r\ndef sample_get_histograms(client, project, logstore):\r\n    topic = 'TestTopic_2'\r\n    From = int(time.time())-3600\r\n    To = int(time.time())\r\n    request = GetHistogramsRequest(project, logstore, From, To, topic)\r\n    response = client.get_histograms(request)\r\n    response.log_print()\r\n\r\n\r\ndef sample_machine_group(client, project) :\r\n\n    machine_group = MachineGroupDetail(\"sample-group\", \"ip\", [\"127.0.0.1\", \"127.0.0.2\"], \"Armory\", {\"externalName\" : \"test-1\", \"groupTopic\":\"yyy\"})\r\n\r\n    res = client.create_machine_group(project, machine_group)\r\n    res.log_print()\r\n\n    res = client.list_machine_group(project)\r\n    res.log_print()\r\n\r\n    res = client.get_machine_group(project, \"sample-group\")\r\n    res.log_print()\r\n\r\n\r\n    machine_group = MachineGroupDetail(\"sample-group\", \"userdefined\", [\"127.0.0.1\", \"127.0.0.3\"], \"Armory\", {\"externalName\" : \"test-1\", \"groupTopic\":\"yyy\"})\r\n    res = client.update_machine_group(project, machine_group)\r\n    res.log_print()\r\n\r\n    res = client.get_machine_group(project, \"stt-group\")\r\n    res.log_print()\r\n\r\ndef sample_index(client, project, logstore) :\n    line_config = IndexLineConfig([\" \", \"\\\\t\", \"\\\\n\", \",\"], False, [\"key_1\", \"key_2\"])\r\n\r\n    key_config_list = {}\r\n    key_config_list[\"key_1\"] = IndexKeyConfig([\",\", \"\\t\", \";\"], True)\r\n\r\n    index_detail = IndexConfig(7, line_config, key_config_list)\r\n\n    res = client.create_index(project, logstore, index_detail)\r\n\r\n    res.log_print()\r\n\r\n    key_config_list = {}\r\n    key_config_list[\"key_1\"] = IndexKeyConfig([\",\", \"\\t\", \";\"], True)\r\n\r\n    index_detail = IndexConfig(7, line_config, key_config_list)\r\n\n    res = client.update_index(project, logstore, index_detail)\r\n\r\n    res.log_print()\r\n\r\n    res = client.get_index_config(project, logstore)\r\n    res.log_print()\r\n\r\n    res = client.delete_index(project, logstore)\r\n    res.log_print()\r\n\r\ndef sample_logtail_config(client, project, logstore) :\n    logtail_config = CommonRegLogConfigDetail(\"stt-logtail\", logstore, \"http://cn-hangzhou-devcommon-intranet.sls.aliyuncs.com\", \"/apsara/xxx\", \"*.LOG\",\n            \"%Y-%m-%d %H:%M:%S\", \"xxx.*\", \"(.*)(.*)\" , [\"time\", \"value\"])\r\n\r\n    res = client.create_logtail_config(project, logtail_config)\r\n    res.log_print()\r\n\r\n    res = client.get_logtail_config(project, 'stt-logtail')\r\n    res.log_print()\r\n\r\n    logtail_config = ApsaraLogConfigDetail(\"stt-logtail\", logstore, \"http://cn-hangzhou-devcommon-intranet.sls.aliyuncs.com\", \"/apsara/xxx\", \"yyy.LOG\")\r\n    res = client.update_logtail_config(project, logtail_config)\r\n    res.log_print()\r\n\r\n    res = client.get_logtail_config(project, 'stt-logtail')\r\n    res.log_print()\r\n\r\n    res = client.delete_logtail_config(project, \"stt-logtail\")\r\n    res.log_print()\r\n\r\ndef sample_acl(client, project, logstore) :\r\n    acl_config = AclConfig(\"ANONYMOUS\", [\"ADMIN\"])\r\n    res = client.update_project_acl(project, \"grant\", acl_config)\r\n    res.log_print()\r\n\r\n    res = client.list_project_acl(project)\r\n    res.log_print()\r\n\r\n    acl_config = AclConfig(\"1655928604919847\", [\"READ\", \"WRITE\"])\r\n    res = client.update_logstore_acl(project,  logstore, \"grant\", acl_config)\r\n    res.log_print()\r\n\r\n    res = client.list_logstore_acl(project, logstore)\r\n    res.log_print()\r\n    exit(0)\r\n\r\ndef sample_apply_config(client, project):\r\n    logtail_config = CommonRegLogConfigDetail(\"stt-logtail\", logstore, \"http://cn-hangzhou-devcommon-intranet.sls.aliyuncs.com\", \"/apsara/xxx\", \"*.LOG\",\n            \"%Y-%m-%d %H:%M:%S\", \"xxx.*\", \"(.*)(.*)\" , [\"time\", \"value\"])\r\n\r\n #   res = client.create_logtail_config(project, logtail_config)\r\n    res = client.get_machine_group_applied_configs(project, \"stt-group\")\r\n    res.log_print()\r\n\r\n    res = client.get_config_applied_machine_groups(project, \"stt-logtail\")\r\n    res.log_print()\r\n\r\n    res = client.apply_config_to_machine_group(project, \"stt-logtail\", \"stt-group\")\r\n    res.log_print()\r\n\r\ndef sample_logstore(client, project, logstore) :\n    res = client.create_logstore(project, logstore, 1, 1)\r\n    res.log_print()\r\n\r\n    res = client.update_logstore(project, logstore, 1, 10)\r\n    res.log_print()\r\n\r\n    res = client.list_logstore(project, logstore)\r\n    res.log_print()\r\n\n    res = client.delete_logstore(project, logstore)\r\n    res.log_print()\r\n\r\n\r\nif __name__=='__main__':\r\n    endpoint = 'http://cn-hangzhou-staging-intranet.sls.aliyuncs.com'\r\n    accessKeyId = 'your_access_id'\r\n    accessKey = 'your_access_key'\r\n    project = 'your_project_name'\r\n    logstore = 'your_logstore'\r\n\r\n    client = LogClient(endpoint, accessKeyId, accessKey)\r\n\r\n    sample_logstore(client, project, logstore)\n\r\n    res = client.create_logstore(project, logstore, 1, 1)\r\n    time.sleep(0.1)\r\n\r\n    try :\n        sample_list_logstores(client, project)\r\n        sample_logtail_config(client, project, logstore)\n        sample_machine_group(client, project)\r\n        sample_acl(client, project, logstore)\r\n        sample_apply_config(client, project)\r\n        sample_index(client, project, logstore)\r\n        sample_list_topics(client, project, logstore)\r\n        sample_put_logs(client, project, logstore):\r\n        sample_pull_logs(client, project, logstore)\r\n        sample_get_logs(client, project, logstore)\r\n    except LogException, e:\r\n        print e\r\n\r\n    client.delete_logstore(project, logstore)\r\n\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylertemp%2Faliyun-log-sdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylertemp%2Faliyun-log-sdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylertemp%2Faliyun-log-sdk-python/lists"}