aliyun.sls package

Submodules

aliyun.sls.gethistogramsrequest module

class aliyun.sls.gethistogramsrequest.GetHistogramsRequest(project=None, logstore=None, fromTime=None, toTime=None, topic=None, query=None)[source]

Bases: aliyun.sls.slsrequest.SLSRequest

The request used to get histograms of a query from sls.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • fromTime (int) – the begin time
  • toTime (int) – the end time
  • topic (string) – topic name of logs
  • query (string) – user defined query
get_from()[source]

Get begin time

Returns:int, begin time
get_logstore()[source]

Get logstore name

Returns:string, logstore name.
get_query()[source]

Get user defined query

Returns:string, user defined query
get_to()[source]

Get end time

Returns:int, end time
get_topic()[source]

Get topic name

Returns:string, topic name
set_from(fromTime)[source]

Set begin time

Parameters:fromTime (int) – begin time
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_query(query)[source]

Set user defined query

Parameters:query (string) – user defined query
set_to(toTime)[source]

Set end time

Parameters:toTime (int) – end time
set_topic(topic)[source]

Set topic name

Parameters:topic (string) – topic name

aliyun.sls.gethistogramsresponse module

class aliyun.sls.gethistogramsresponse.GetHistogramsResponse(resp, header)[source]

Bases: aliyun.sls.slsresponse.SLSResponse

The response of the GetHistograms API from sls.

Parameters:
  • resp (dict) – GetHistogramsResponse HTTP response body
  • header (dict) – GetHistogramsResponse HTTP response header
get_histograms()[source]

Get histograms on the requested time range: [from, to)

Returns:Histogram list, histograms on the requested time range: [from, to)
get_total_count()[source]

Get total logs’ count that current query hits

Returns:int, total logs’ count that current query hits
is_completed()[source]

Check if the histogram is completed

Returns:bool, true if this histogram is completed
sls_print()[source]

aliyun.sls.getlogsrequest module

class aliyun.sls.getlogsrequest.GetLogsRequest(project=None, logstore=None, fromTime=None, toTime=None, topic=None, query=None, line=None, offset=None, reverse=None)[source]

Bases: aliyun.sls.slsrequest.SLSRequest

The request used to get logs by a query from sls.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • fromTime (int) – the begin time
  • toTime (int) – the end time
  • topic (string) – topic name of logs
  • query (string) – user defined query
  • line (int) – max line number of return logs
  • offset (int) – line offset of return logs
  • reverse (bool) – if reverse is set to true, the query will return the latest logs first
get_from()[source]

Get begin time

Returns:int, begin time
get_line()[source]

Get max line number of return logs

Returns:int, max line number of return logs
get_logstore()[source]

Get logstore name

Returns:string, logstore name
get_offset()[source]

Get line offset of return logs

Returns:int, line offset of return logs
get_query()[source]

Get user defined query

Returns:string, user defined query
get_reverse()[source]

Get request reverse flag

Returns:bool, reverse flag
get_to()[source]

Get end time

Returns:int, end time
get_topic()[source]

Get topic name

Returns:string, topic name
set_from(fromTime)[source]

Set begin time

Parameters:fromTime (int) – begin time
set_line(line)[source]

Set max line number of return logs

Parameters:line (int) – max line number of return logs
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_offset(offset)[source]

Set line offset of return logs

Parameters:offset (int) – line offset of return logs
set_query(query)[source]

Set user defined query

Parameters:query (string) – user defined query
set_reverse(reverse)[source]

Set request reverse flag

Parameters:reverse (bool) – reverse flag
set_to(toTime)[source]

Set end time

Parameters:toTime (int) – end time
set_topic(topic)[source]

Set topic name

Parameters:topic (string) – topic name

aliyun.sls.getlogsresponse module

class aliyun.sls.getlogsresponse.GetLogsResponse(resp, header)[source]

Bases: aliyun.sls.slsresponse.SLSResponse

The response of the GetLog API from sls.

Parameters:
  • resp (dict) – GetLogsResponse HTTP response body
  • header (dict) – GetLogsResponse HTTP response header
get_count()[source]

Get log number from the response

Returns:int, log number
get_logs()[source]

Get all logs from the response

Returns:QueriedLog list, all log data
is_completed()[source]

Check if the get logs query is completed

Returns:bool, true if this logs query is completed
sls_print()[source]

aliyun.sls.histogram module

class aliyun.sls.histogram.Histogram(fromTime, toTime, count, progress)[source]

The class used to present the result of log histogram status. For every log histogram, it contains : from/to time range, hit log count and query completed status.

Parameters:
  • fromTime (int) – the begin time
  • toTime (int) – the end time
  • count (int) – log count of histogram that query hits
  • progress (string) – histogram query status(Complete or InComplete)
get_count()[source]

Get log count of histogram that query hits

Returns:int, log count of histogram that query hits
get_from()[source]

Get begin time

Returns:int, begin time
get_to()[source]

Get end time

Returns:int, end time
is_completed()[source]

Check if the histogram is completed

Returns:bool, true if this histogram is completed
sls_print()[source]

aliyun.sls.listlogstoresrequest module

class aliyun.sls.listlogstoresrequest.ListLogstoresRequest(project=None)[source]

Bases: aliyun.sls.slsrequest.SLSRequest

The request used to list log store from sls.

Parameters:project (string) – project name

aliyun.sls.listlogstoresresponse module

class aliyun.sls.listlogstoresresponse.ListLogstoresResponse(resp, header)[source]

Bases: aliyun.sls.slsresponse.SLSResponse

The response of the ListLogstores API from sls.

Parameters:
  • resp (dict) – ListLogstoresResponse HTTP response body
  • header (dict) – ListLogstoresResponse HTTP response header
get_count()[source]

Get total count of logstores from the response

Returns:int, the number of total logstores from the response
get_logstores()[source]

Get all the logstores from the response

Returns:list, all logstores
sls_print()[source]

aliyun.sls.listtopicsrequest module

class aliyun.sls.listtopicsrequest.ListTopicsRequest(project=None, logstore=None, token=None, line=None)[source]

Bases: aliyun.sls.slsrequest.SLSRequest

The request used to get topics of a query from sls.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • token (string) – the start token to list topics
  • line (int) – max topic counts to return
get_line()[source]

Get max topic counts to return

Returns:int, max topic counts to return
get_logstore()[source]

Get logstore name

Returns:string, logstore name.
get_token()[source]

Get start token to list topics

Returns:string, start token to list topics
set_line(line)[source]

Set max topic counts to return

Parameters:line (int) – max topic counts to return
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_token(token)[source]

Set start token to list topics

Parameters:token (string) – start token to list topics

aliyun.sls.listtopicsresponse module

class aliyun.sls.listtopicsresponse.ListTopicsResponse(resp, header)[source]

Bases: aliyun.sls.slsresponse.SLSResponse

The response of the ListTopic API from sls.

Parameters:
  • resp (dict) – ListTopicsResponse HTTP response body
  • header (dict) – ListTopicsResponse HTTP response header
get_count()[source]

Get the number of all the topics from the response

Returns:int, the number of all the topics from the response
get_next_token()[source]

Return the next token from the response. If there is no more topic to list, it will return None

Returns:string, next token used to list more topics
get_topics()[source]

Get all the topics from the response

Returns:list, topic list
sls_print()[source]

aliyun.sls.logitem module

class aliyun.sls.logitem.LogItem(timestamp=None, contents=None)[source]

LogItem used to present a log, it contains log time and multiple key/value pairs to present the log contents.

Parameters:
  • timestamp (int) – time of the log item, the default time is the now time.
  • contents (tuple(key-value) list) – the data of the log item, including many (key,value) pairs.
get_contents()[source]

Get log contents

Returns:tuple(key-value) list, log contents.
get_time()[source]

Get log time

Returns:int, log time
push_back(key, value)[source]

Append a key/value pair as a log content to the log

Parameters:
  • key (string) – log content key
  • value (string) – log content value
set_contents(contents)[source]

Set log contents

Parameters:contents (tuple(key-value) list) – log contents (key-value pair list)
set_time(timestamp)[source]

Set log time

Parameters:timestamp (int) – log time
sls_print()[source]

aliyun.sls.putlogsrequest module

class aliyun.sls.putlogsrequest.PutLogsRequest(project=None, logstore=None, topic=None, source=None, logitems=None)[source]

Bases: aliyun.sls.slsrequest.SLSRequest

The request used to send data to sls.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • topic (string) – topic name
  • source (string) – source of the logs
  • logitems (list<LogItem>) – log data
get_log_items()[source]

Get all the log data

Returns:LogItem list, log data
get_logstore()[source]

Get logstore name

Returns:string, logstore name
get_source()[source]

Get log source

Returns:string, log source
get_topic()[source]

Get topic name

Returns:string, topic name
set_log_items(logitems)[source]

Set the log data

Parameters:logitems (LogItem list) – log data
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_source(source)[source]

Set log source

Parameters:source (string) – log source
set_topic(topic)[source]

Set topic name

Parameters:topic (string) – topic name

aliyun.sls.putlogsresponse module

class aliyun.sls.putlogsresponse.PutLogsResponse(header)[source]

Bases: aliyun.sls.slsresponse.SLSResponse

The response of the PutLogs API from sls.

Parameters:header (dict) – PutLogsResponse HTTP response header
sls_print()[source]

aliyun.sls.queriedlog module

class aliyun.sls.queriedlog.QueriedLog(timestamp, source, contents)[source]

The QueriedLog is a log of the GetLogsResponse which obtained from the sls.

Parameters:
  • timestamp (int) – log timestamp
  • source (string) – log source
  • contents (dict) – log contents, content many key/value pair
get_contents()[source]

Get log contents

Returns:dict, log contents
get_source()[source]

Get log source

Returns:string, log source
get_time()[source]

Get log time

Returns:int, log time
sls_print()[source]

aliyun.sls.sls_logs_pb2 module

class aliyun.sls.sls_logs_pb2.Log(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
CONTENTS_FIELD_NUMBER = 2
Clear()
ClearField(field_name)
class Content(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0391AF70>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
KEY_FIELD_NUMBER = 1
Key

Magic attribute generated for “Key” proto field.

ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

VALUE_FIELD_NUMBER = 2
Value

Magic attribute generated for “Value” proto field.

WhichOneof(oneof_name)

Returns the name of the currently set field inside a oneof, or None.

Log.Contents

Magic attribute generated for “Contents” proto field.

Log.DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0391AFD0>
Log.FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static Log.FromString(s)
Log.HasField(field_name)
Log.IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
Log.ListFields()
Log.MergeFrom(msg)
Log.MergeFromString(serialized)
static Log.RegisterExtension(extension_handle)
Log.SerializePartialToString()
Log.SerializeToString()
Log.SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

Log.TIME_FIELD_NUMBER = 1
Log.Time

Magic attribute generated for “Time” proto field.

Log.WhichOneof(oneof_name)

Returns the name of the currently set field inside a oneof, or None.

class aliyun.sls.sls_logs_pb2.LogGroup(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0391F090>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
LOGS_FIELD_NUMBER = 1
ListFields()
Logs

Magic attribute generated for “Logs” proto field.

MergeFrom(msg)
MergeFromString(serialized)
RESERVED_FIELD_NUMBER = 2
static RegisterExtension(extension_handle)
Reserved

Magic attribute generated for “Reserved” proto field.

SOURCE_FIELD_NUMBER = 4
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

Source

Magic attribute generated for “Source” proto field.

TOPIC_FIELD_NUMBER = 3
Topic

Magic attribute generated for “Topic” proto field.

WhichOneof(oneof_name)

Returns the name of the currently set field inside a oneof, or None.

aliyun.sls.slsclient module

class aliyun.sls.slsclient.SLSClient(endpoint, accessKeyId, accessKey)[source]

Bases: object

Construct the SLSClient with endpoint, accessKeyId, accessKey.

Parameters:
Version = '0.4.0'
get_histograms(request)[source]

Get histograms of requested query from SLS. Unsuccessful opertaion will cause an SLSException.

Parameters:request (GetHistogramsRequest) – the GetHistograms request parameters class.
Returns:GetHistogramsResponse
Raise:SLSException
get_logs(request)[source]

Get logs from SLS. Unsuccessful opertaion will cause an SLSException.

Parameters:request (GetLogsRequest) – the GetLogs request parameters class.
Returns:GetLogsResponse
Raise:SLSException
get_unicode(key)[source]
list_logstores(request)[source]

List all logstores of requested project. Unsuccessful opertaion will cause an SLSException.

Parameters:request (ListLogstoresRequest) – the ListLogstores request parameters class.
Returns:ListLogStoresResponse
Raise:SLSException
list_topics(request)[source]

List all topics in a logstore. Unsuccessful opertaion will cause an SLSException.

Parameters:request (ListTopicsRequest) – the ListTopics request parameters class.
Returns:ListTopicsResponse
Raise:SLSException
put_logs(request)[source]

Put logs to SLS. Unsuccessful opertaion will cause an SLSException.

Parameters:request (PutLogsRequest) – the PutLogs request parameters class
Returns:PutLogsResponse
Raise:SLSException
aliyun.sls.slsclient.USER_AGENT = 'sls-python-sdk-v-0.4.6'

SlsClient class is the main class in the SDK. It can be used to communicate with SLS server to put/get data.

Author:sls_dev

aliyun.sls.slsexception module

exception aliyun.sls.slsexception.SLSException(errorCode, errorMessage, requestId='')[source]

Bases: exceptions.Exception

The Exception of the sls request & response.

Parameters:
  • errorCode (string) – SLS error code
  • errorMessage (string) – detailed information for the exception
  • requestId (string) – the request id of the response, ‘’ is set if client error
get_error_code()[source]

return error code of exception

Returns:string, error code of exception.
get_error_message()[source]

return error message of exception

Returns:string, error message of exception.
get_request_id()[source]

return request id of exception. if client exception, request id is empty string

Returns:string, request id of exception.

aliyun.sls.slsrequest module

class aliyun.sls.slsrequest.SLSRequest(project)[source]

The base request of all sls request.

Parameters:project (string) – project name
get_project()[source]

Get project name

Returns:string, project name.
set_project(project)[source]

Set project name

Parameters:project (string) – project name

aliyun.sls.slsresponse module

class aliyun.sls.slsresponse.SLSResponse(headers)[source]

The base response class of all sls response.

Parameters:headers (dict) – HTTP response header
get_all_headers()[source]

Get all http header of the response

Returns:dict, response header
get_header(key)[source]

Get specified http header of the response, ‘’ will be return if not set.

Parameters:key (string) – the key to get header
Returns:string, response header
get_request_id()[source]

Get the request id of the response. ‘’ will be return if not set.

Returns:string, request id
sls_print()[source]

aliyun.sls.util module

class aliyun.sls.util.Util[source]
static cal_md5(content)[source]
static canonicalized_resource(resource, params)[source]
static canonicalized_sls_headers(headers)[source]
static compress_data(data)[source]
static get_host_ip(slsHost)[source]

If it is not match your local ip, you should fill the PutLogsRequest parameter source by yourself.

static get_request_authorization(method, resource, key, params, headers)[source]
static hmac_sha1(content, key)[source]
static is_row_ip(ip)[source]
static url_encode(params)[source]

Module contents