### Install pydatahub from source Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Manual installation steps for building from the source repository. ```shell $ virtualenv pydatahub_env $ source pydatahub_env/bin/activate $ git clone pydatahub $ cd pydatahub $ python setup.py install ``` -------------------------------- ### Manual Dependency Installation Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/dependency/readme.txt Use these commands to install setuptools and pip manually if the environment lacks pip. ```bash 0. unzip setuptools-39.2.0.zip 1. cd setuptools-39.2.0 2. python setup.py install 3. cd .. 4. tar zxvf pip-10.0.1.tar.gz 5. cd pip-10.0.1 6. python setup.py install 7. cd .. ``` -------------------------------- ### Datahub SDK Usage Examples Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Comprehensive examples for initializing the DataHub client, managing projects, creating topics, and putting records. ```python from datahub import DataHub # with credential (https://github.com/aliyun/credentials-python/) from alibabacloud_credentials.client import Client as CredClient from alibabacloud_credentials.models import Config as CredConfig config = CredConfig( type='access_key', access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'), access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'), ) credential = CredClient(config) dh = DataHub.from_credential(credential, '**your-end-point**') # with access # dh = DataHub('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**') # dh = DataHub.from_access('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**') # with security token # dh = DataHub('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**', security_token='**your-security-token**') # dh = DataHub.from_access('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**', security_token='**your-security-token**') # ============================= create project ============================= project_name = 'my_project_name' comment = 'my project' dh.create_project(project_name, comment) # ============================= get project ============================= project_result = dh.get_project('pydatahub_test') print(project_result) # ============================= create tuple topic ============================= from datahub.models import RecordSchema, FieldType topic_name='tuple_topic_test' shard_count = 3 life_cycle = 7 comment = 'tuple topic' record_schema = RecordSchema.from_lists(['bigint_field', 'string_field', 'double_field', 'bool_field', 'time_field'], [FieldType.BIGINT, FieldType.STRING, FieldType.DOUBLE, FieldType.BOOLEAN, FieldType.TIMESTAMP]) dh.create_tuple_topic(project_name, topic_name, shard_count, life_cycle, record_schema, comment) # ============================= create blob topic ============================= topic_name='blob_topic_test' shard_count = 3 life_cycle = 7 comment = 'blob topic' dh.create_blob_topic(project_name, topic_name, shard_count, life_cycle, comment) # ============================= get topic ============================= topic_result = dh.get_topic(project_name, topic_name) print(topic_result) print(topic_result.record_schema) # ============================= list shard ============================= shards_result = dh.list_shard(project_name, topic_name) print(shards_result) # ============================= put tuple records ============================= from datahub.models import TupleRecord # put records by shard is recommended records0 = [] record0 = TupleRecord(schema=record_schema, values=[1, 'yc1', 10.01, True, 1455869335000000]) record0.put_attribute('AK', '47') records0.append(record0) put_result = dh.put_records_by_shard('pydatahub_test', 'tuple_topic_test', "0", records0) ``` -------------------------------- ### Install pydatahub via pip Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Standard installation method using pip. ```shell $ sudo pip install pydatahub ``` -------------------------------- ### Install tox for testing Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Install the tox automation tool to run project tests. ```shell $ pip install -U tox ``` -------------------------------- ### Scripted Dependency Installation Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/dependency/readme.txt Execute the provided shell script to install project dependencies. ```bash 0. sudo ./install_dependency.sh ``` -------------------------------- ### Clone DataHub SDK Repository Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Command to clone the SDK repository for development installation. ```bash git clone https://github.com/aliyun/aliyun-datahub-sdk-python.git ``` -------------------------------- ### Get Records Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.md Demonstrates retrieving cursors and fetching tuple or blob records from a specific shard. ```python # ============================= get cursor ============================= from datahub.models import CursorType cursor_result = dh.get_cursor(project_name, topic_name, '0', CursorType.OLDEST) print(cursor_result) # ============================= get blob records ============================= limit = 10 blob_cursor_result = dh.get_cursor(project_name, topic_name, '0', CursorType.OLDEST) get_result = dh.get_blob_records(project_name, topic_name, '0', blob_cursor_result.cursor, limit) print(get_result) print(get_result.records) print(get_result.records[0]) # ============================= get tuple records ============================= limit = 10 tuple_cursor_result = dh.get_cursor(project_name, topic_name, '0', CursorType.OLDEST) get_result = dh.get_tuple_records(project_name, topic_name, '0', record_schema, tuple_cursor_result.cursor, limit) print(get_result) print(get_result.records) print(get_result.records[0].values) ``` -------------------------------- ### Install dependencies offline Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Install required packages from the local dependency folder when network access is unavailable. ```shell $ cd dependency $ pip install -r first.txt $ pip install -r second.txt ``` -------------------------------- ### Get Tuple Records from DataHub Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Fetches tuple records from a topic using a schema, cursor, and limit. ```python limit = 10 tuple_cursor_result = dh.get_cursor(project_name, topic_name, '0', CursorType.OLDEST) get_result = dh.get_tuple_records(project_name, topic_name, '0', record_schema, tuple_cursor_result.cursor, limit) print(get_result) print(get_result.records) print(get_result.records[0].values) ``` -------------------------------- ### Get Blob Records from DataHub Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Fetches blob records from a topic using a cursor and a specified limit. ```python limit = 10 blob_cursor_result = dh.get_cursor(project_name, topic_name, '0', CursorType.OLDEST) get_result = dh.get_blob_records(project_name, topic_name, '0', blob_cursor_result.cursor, limit) print(get_result) print(get_result.records) print(get_result.records[0]) ``` -------------------------------- ### Get DataHub Cursor Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Retrieves a cursor for a specific shard using a defined cursor type. ```python from datahub.models import CursorType cursor_result = dh.get_cursor(project_name, topic_name, '0', CursorType.OLDEST) print(cursor_result) ``` -------------------------------- ### Initialize DataHub Client Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Demonstrates various ways to instantiate the DataHub client, including configurations for protocol types, schema registration, and compression formats. ```pycon >>> datahub = DataHub('**your access id**', '**your access key**', '**endpoint**') >>> datahub_pb = DataHub('**your access id**', '**your access key**', '**endpoint**', protocol_type=DatahubProtocolType.PB) >>> datahub_batch = DataHub('**your access id**', '**your access key**', '**endpoint**', protocol_type=DatahubProtocolType.BATCH, enable_schema_register=True) >>> datahub_lz4 = DataHub('**your access id**', '**your access key**', '**endpoint**', compress_format=CompressFormat.LZ4) >>> >>> project_result = datahub.get_project('datahub_test') >>> >>> print(project_result is None) >>> ``` -------------------------------- ### Initialize DataHub Client Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.md Demonstrates how to authenticate and initialize the DataHub client using credentials or access keys. ```python from datahub import DataHub # with credential (https://github.com/aliyun/credentials-python/) from alibabacloud_credentials.client import Client as CredClient from alibabacloud_credentials.models import Config as CredConfig config = CredConfig( type='access_key', access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'), access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'), ) credential = CredClient(config) dh = DataHub.from_credential(credential, '**your-end-point**') # with access # dh = DataHub('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**') # dh = DataHub.from_access('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**') # with security token # dh = DataHub('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**', security_token='**your-security-token**') # dh = DataHub.from_access('**your-access-id**', '**your-secret-access-key**', endpoint='**your-end-point**', security_token='**your-security-token**') ``` -------------------------------- ### Manage Projects and Topics Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.md Covers creating and retrieving projects and topics, including schema definition for tuple topics. ```python # ============================= create project ============================= project_name = 'my_project_name' comment = 'my project' dh.create_project(project_name, comment) # ============================= get project ============================= project_result = dh.get_project('pydatahub_test') print(project_result) # ============================= create tuple topic ============================= from datahub.models import RecordSchema, FieldType topic_name='tuple_topic_test' shard_count = 3 life_cycle = 7 comment = 'tuple topic' record_schema = RecordSchema.from_lists(['bigint_field', 'string_field', 'double_field', 'bool_field', 'time_field'], [FieldType.BIGINT, FieldType.STRING, FieldType.DOUBLE, FieldType.BOOLEAN, FieldType.TIMESTAMP]) dh.create_tuple_topic(project_name, topic_name, shard_count, life_cycle, record_schema, comment) # ============================= create blob topic ============================= topic_name='blob_topic_test' shard_count = 3 life_cycle = 7 comment = 'blob topic' dh.create_tuple_topic(project_name, topic_name, shard_count, life_cycle, comment) # ============================= get topic ============================= topic_result = dh.get_topic(project_name, topic_name) print(topic_result) print(topic_result.record_schema) # ============================= list shard ============================= shards_result = dh.list_shard(project_name, topic_name) print(shards_result) ``` -------------------------------- ### Run project tests Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Execute the test suite using tox after configuring datahub.ini. ```shell $ tox ``` -------------------------------- ### create_project Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Creates a new project with a specified name and comment. ```APIDOC ## create_project(project_name, comment) ### Description Creates a new project by given name and comment. ### Parameters - **project_name** (str) - Required - project name - **comment** (str) - Required - description of project ``` -------------------------------- ### init_and_get_subscription_offset Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Opens a subscription offset session. ```APIDOC ## init_and_get_subscription_offset(project_name, topic_name, sub_id, shard_ids) ### Description Open subscription offset session. ### Parameters - **project_name** - project name - **topic_name** - topic name - **sub_id** - subscription id - **shard_ids** - shard ids ### Returns - offset info (datahub.models.InitAndGetSubscriptionOffsetResult) ``` -------------------------------- ### Put Records Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.md Shows how to ingest tuple and blob records into DataHub, with a recommendation to use shard-based ingestion. ```python # ============================= put tuple records ============================= from datahub.models import TupleRecord # put records by shard is recommended records0 = [] record0 = TupleRecord(schema=record_schema, values=[1, 'yc1', 10.01, True, 1455869335000000]) record0.put_attribute('AK', '47') records0.append(record0) put_result = dh.put_records_by_shard('pydatahub_test', 'tuple_topic_test', "0", records0) # records0 = [] # record0 = TupleRecord(schema=record_schema, values=[1, 'yc1', 10.01, True, 1455869335000000]) # record0.shard_id = '0' # record0.put_attribute('AK', '47') # records0.append(record0) # put_result = dh.put_records('pydatahub_test', 'tuple_topic_test', records0) print(put_result) # ============================= put blob records ============================= from datahub.models import BlobRecord # put records by shard is recommended data = None with open(os.path.join(root_path, 'tests/resources/datahub.png'), 'rb') as f: data = f.read() records1 = [] record1 = BlobRecord(blob_data=data) record1.put_attribute('a', 'b') records1.append(record1) put_result = dh.put_records_by_shard('pydatahub_test', 'blob_topic_test', "0" records1) # records1 = [] # record1 = BlobRecord(blob_data=data) # record1.shard_id = '0' # record1.put_attribute('a', 'b') # records1.append(record1) # put_result = dh.put_records('pydatahub_test', 'blob_topic_test', records1) print(put_result) ``` -------------------------------- ### list_project Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Lists all project names. ```APIDOC ## list_project() ### Description List all project names. ### Returns - projects in datahub server (datahub.models.results.ListProjectResult) ``` -------------------------------- ### DataHub Client Initialization Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Initializes the main DataHub client instance required for interacting with the service. ```APIDOC ## DataHub(access_id, access_key, endpoint, ...) ### Description Initializes the DataHub client to perform operations on projects, topics, and connectors. ### Parameters - **access_id** (str) - Required - Aliyun Access ID - **access_key** (str) - Required - Aliyun Access Key - **endpoint** (str) - Optional - Rest service URL - **compress_format** (CompressFormat) - Optional - Compression format (NONE, LZ4, ZLIB, DEFLATE) - **protocol_type** (DatahubProtocolType) - Optional - Protocol type for data transmission - **enable_schema_register** (bool) - Optional - Enable schema register in batch mode ``` -------------------------------- ### get_project(project_name) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves project details by name. ```APIDOC ## get_project(project_name) ### Description Get a project by given name. ### Parameters - **project_name** (string) - Required - project name ### Returns - **GetProjectResult** (datahub.models.GetProjectResult) - the project details ### Exceptions - **ResourceNotFoundException** - if project does not exist - **InvalidParameterException** - if project_name is empty ``` -------------------------------- ### Create a RecordSchema Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Construct a schema by providing lists of field names and their corresponding types. ```pycon >>> schema = RecordSchema.from_lists( ['bigint_field' , 'string_field' , 'double_field' , 'bool_field' , 'time_field'], [FieldType.BIGINT, FieldType.STRING, FieldType.DOUBLE, FieldType.BOOLEAN, FieldType.TIMESTAMP] ) >>> ``` -------------------------------- ### datahub.client.ProducerConfig Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Configuration class for initializing a Datahub producer client. ```APIDOC ## class datahub.client.ProducerConfig ### Description Configuration object for the Datahub producer, defining authentication, endpoint, and performance tuning parameters. ### Parameters - **access_id** (string) - Required - Aliyun access id - **access_key** (string) - Required - Aliyun access key - **endpoint** (string) - Required - Datahub endpoint - **protocol_type** (DatahubProtocolType) - Optional - Protocol type for datahub client - **compress_format** (CompressFormat) - Optional - Compress format for records data - **credential** (object) - Optional - Credential object - **retry_times** (int) - Optional - Retry times when request error - **async_thread_limit** (int) - Optional - Thread num limit for thread pool in message writer - **thread_queue_limit** (int) - Optional - Task num limit for queue in thread pool in message writer - **logging_level** (int) - Optional - Logging level - **logging_filename** (string) - Optional - Logging file name - **max_async_buffer_records** (int) - Optional - Max buffer records number to PutRecords once. Only valid when write async. - **max_async_buffer_size** (int) - Optional - Max buffer size to PutRecords once. Only valid when write async. - **max_async_buffer_time** (int) - Optional - Max buffer time to PutRecords once. Only valid when write async. - **max_record_pack_queue_limit** (int) - Optional - Max ready record pack limit for queue. Only valid when write async. ``` -------------------------------- ### list_topic_schema(project_name, topic_name, page_number=-1, page_size=-1) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Lists the schema information for a specific topic. ```APIDOC ## list_topic_schema(project_name, topic_name, page_number=-1, page_size=-1) ### Description List all schema of a topic. ### Parameters - **project_name** - project_name - **topic_name** - topic_name - **page_number** - page number - **page_size** - page size ### Returns - **all schema info of a topic** ``` -------------------------------- ### list_topic(project_name) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves all topics within a specified project. ```APIDOC ## list_topic(project_name) ### Description Get all topics of a project. ### Parameters - **project_name** - project name ### Returns - **all topics of the project** (datahub.models.ListTopicResult) ``` -------------------------------- ### register_topic_schema(project_name, topic_name, schema) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Register a schema in a topic. ```APIDOC ## register_topic_schema(project_name, topic_name, schema) ### Description Register a schema in a topic. ### Parameters - **project_name** (string) - project name - **topic_name** (string) - topic name - **schema** (object) - schema ### Returns - **version id** (string) ``` -------------------------------- ### get_topic(project_name, topic_name) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves topic information. ```APIDOC ## get_topic(project_name, topic_name) ### Description Get a topic. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name ### Returns - **GetTopicResult** (datahub.models.GetTopicResult) - topic info ### Exceptions - **ResourceNotFoundException** - if the project or topic does not exist - **InvalidParameterException** - if the project name or topic name is empty ``` -------------------------------- ### heart_beat Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Constructs a heartbeat to inform the server of consumer status. ```APIDOC ## heart_beat(project_name, topic_name, consumer_group, consumer_id, version_id, hold_shard_list, read_end_shard_list) ### Description Construct heartbeat with server that server know consumer status. ### Parameters - **project_name** - project name - **topic_name** - topic name - **consumer_group** - consumer group use sub_id you want to join - **consumer_id** - consumer id obtained at the time of join group - **version_id** - offset version id obtained at the time of join group - **hold_shard_list** - the shard list held by consumer - **read_end_shard_list** - the shard list have been read finished ### Returns - heartbeat result contains version id, shard list and total plan ``` -------------------------------- ### split_shard(project_name, topic_name, shard_id, split_key='') Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Split a shard. ```APIDOC ## split_shard(project_name, topic_name, shard_id, split_key='') ### Description Split a shard. ### Parameters - **project_name** (string) - project name - **topic_name** (string) - topic name - **shard_id** (string) - split shard id - **split_key** (string) - split key, if not given, choose the median ### Returns - **datahub.models.SplitShardResult** - shards info after split ``` -------------------------------- ### list_subscription(project_name, topic_name, query_key, page_index, page_size) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Queries subscriptions for a topic with pagination support. ```APIDOC ## list_subscription(project_name, topic_name, query_key, page_index, page_size) ### Description Query subscription in range [start, end) where start = (page_index - 1) * page_size + 1. ### Parameters - **project_name** - project name - **topic_name** - topic name - **query_key** - query key for search - **page_index** - page index - **page_size** - page size ### Returns - **subscription info list** (datahub.models.results.ListSubscriptionResult) ``` -------------------------------- ### create_connector Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Creates a new data connector for a specified project and topic. ```APIDOC ## create_connector(project_name, topic_name, connector_type, column_fields, config, start_time=-1) ### Description Creates a data connector for a given project and topic. ### Parameters - **project_name** (str) - Required - project name - **topic_name** (str) - Required - topic name - **connector_type** (ConnectorType) - Required - connector type - **column_fields** (list) - Required - column fields - **config** (ConnectorConfig) - Required - connector config - **start_time** (int) - Optional - start timestamp in milliseconds ### Returns - **connector_id** (str) - The ID of the created connector. ``` -------------------------------- ### Version increment commands Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.md Use these commands to update the project version based on the type of change being released. ```bash bumpversion patch ``` ```bash bumpversion minor ``` ```bash bumpversion major ``` -------------------------------- ### Manipulate TupleRecord values Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Demonstrates creating a TupleRecord with a schema and performing value retrieval and updates using field names or indices. ```pycon >>> schema = RecordSchema.from_lists(['name', 'id'], [FieldType.STRING, FieldType.STRING]) >>> record = TupleRecord(schema=schema, values=['test', 'test2']) >>> record.values[0:2] >>> ['test', 'test2'] >>> record.set_value('name', 'test1') >>> record.values[0] >>> 'test1' >>> record.set_value(0, 'test3') >>> record.get_value(0) >>> 'test3' >>> record.get_value('name') >>> 'test3' >>> len(record.values) 2 >>> record.has_field('name') True ``` -------------------------------- ### get_metering_info(project_name, topic_name, shard_id) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves metering information for a specific shard. ```APIDOC ## get_metering_info(project_name, topic_name, shard_id) ### Description Get a shard metering info. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **shard_id** (string) - Required - shard id ### Returns - **GetMeteringInfoResult** (datahub.models.GetMeteringInfoResult) - the shard metering info ### Exceptions - **ResourceNotFoundException** - if the project, topic or shard does not exist - **InvalidParameterException** - if the project_name, topic_name or shard_id is empty ``` -------------------------------- ### put_records(project_name, topic_name, record_list) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Publishes a list of records to a topic. ```APIDOC ## put_records(project_name, topic_name, record_list) ### Description Put records to a topic. ### Parameters - **project_name** - project name - **topic_name** - topic name - **record_list** (list) - record list ### Returns - **failed records info** (datahub.models.PutRecordsResult) ``` -------------------------------- ### join_group Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Joins a consumer group. ```APIDOC ## join_group(project_name, topic_name, consumer_group, session_timeout) ### Description Join a consumer group. ### Parameters - **project_name** - project name - **topic_name** - topic name - **consumer_group** - consumer group use sub_id you want to join - **session_timeout** - session timeout ### Returns - consumer id and version id ``` -------------------------------- ### create_tuple_topic Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Creates a new tuple topic within a project. ```APIDOC ## create_tuple_topic(project_name, topic_name, shard_count, life_cycle, record_schema, comment, extend_mode=None) ### Description Create tuple topic. ### Parameters - **project_name** (str) - Required - project name - **topic_name** (str) - Required - topic name - **shard_count** (int) - Required - shard count - **life_cycle** (int) - Required - life cycle - **record_schema** (RecordSchema) - Required - record schema for tuple record type - **comment** (str) - Required - comment - **extend_mode** (any) - Optional - use expansion method to increase shard ``` -------------------------------- ### create_blob_topic Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Creates a new blob topic. ```APIDOC ## create_blob_topic(project_name, topic_name, shard_count, life_cycle, comment, extend_mode) ### Description Creates a new blob topic with the specified configuration. ### Parameters - **project_name** (str) - Required - Project name - **topic_name** (str) - Required - Topic name - **shard_count** (int) - Required - Number of shards - **life_cycle** (int) - Required - Data retention period - **comment** (str) - Required - Topic description - **extend_mode** (any) - Optional - Expansion method for shards ``` -------------------------------- ### get_subscription(project_name, topic_name, sub_id) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves subscription information. ```APIDOC ## get_subscription(project_name, topic_name, sub_id) ### Description Get subscription information. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **sub_id** (string) - Required - subscription id ### Returns - **GetSubscriptionResult** (datahub.models.results.GetSubscriptionResult) - subscription info ### Exceptions - **ResourceNotFoundException** - if the project, topic or subscription does not exist - **InvalidParameterException** - if project_name, topic_name or sub_id is empty ``` -------------------------------- ### list_shard(project_name, topic_name) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Lists all shards associated with a specific topic. ```APIDOC ## list_shard(project_name, topic_name) ### Description List all shards of a topic. ### Parameters - **project_name** - project name - **topic_name** - topic name ### Returns - **shards info** (datahub.models.ListTopicResult) ``` -------------------------------- ### create_subscription Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Creates a subscription to a specific topic. ```APIDOC ## create_subscription(project_name, topic_name, comment, sub_id=None) ### Description Create subscription to a topic. ### Parameters - **project_name** (str) - Required - project name - **topic_name** (str) - Required - topic name - **comment** (str) - Required - comment for subscription - **sub_id** (str) - Optional - custom subscription id ### Returns - **result** (CreateSubscriptionResult) - Contains subscription id. ``` -------------------------------- ### Put Blob Records to DataHub Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/README.rst Reads a file and sends it as a blob record to a specific shard. ```python from datahub.models import BlobRecord # put records by shard is recommended data = None with open(os.path.join(root_path, 'tests/resources/datahub.png'), 'rb') as f: data = f.read() records1 = [] record1 = BlobRecord(blob_data=data) record1.put_attribute('a', 'b') records1.append(record1) put_result = dh.put_records_by_shard('pydatahub_test', 'blob_topic_test', "0" records1) print(put_result) ``` -------------------------------- ### get_connector(project_name, topic_name, connector_id) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves information about a data connector. ```APIDOC ## get_connector(project_name, topic_name, connector_id) ### Description Get a data connector. ### Parameters - **project_name** - project name - **topic_name** - topic name - **connector_id** - connector id, compatible for connector type ### Returns - **data connector info** (datahub.models.GetConnectorResult) ### Exceptions - **ResourceNotFoundException**: if the project, topic or connector not exists - **InvalidParameterException**: if project_name or topic_name is empty; connector_type or config is wrong type ``` -------------------------------- ### list_connector Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Lists data connectors for a topic. ```APIDOC ## list_connector(project_name, topic_name) ### Description Create a data connector. ### Parameters - **project_name** - project name - **topic_name** - topic name ### Returns - data connector names list (datahub.models.ListConnectorResult) ``` -------------------------------- ### wait_shards_ready Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Blocks execution until all shards in a topic reach an 'active' or 'closed' state. ```APIDOC ## wait_shards_ready(project_name, topic_name, timeout=30) ### Description Waits for all shards in a topic to reach an 'active' or 'closed' state. This is typically invoked after creating a topic. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **timeout** (int) - Optional - -1 blocks until ready, otherwise waits for the specified number of seconds. ### Exceptions - **ResourceNotFoundException**: Raised if the project or topic does not exist. - **InvalidParameterException**: Raised if the project name or topic name is empty, or if timeout < 0. - **DatahubException**: Raised if a timeout occurs. ``` -------------------------------- ### get_topic_schema(project_name, topic_name, schema=None, version_id=-1) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves the schema or version ID of a topic. ```APIDOC ## get_topic_schema(project_name, topic_name, schema=None, version_id=-1) ### Description Get the special schema or version id of a topic. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **schema** (string) - Optional - schema - **version_id** (int) - Optional - version id ### Returns - **Result** - schema by version id or version id by schema ### Exceptions - **ResourceNotFoundException** - if the project or topic does not exist - **InvalidParameterException** - if project_name or topic_name is empty ``` -------------------------------- ### put_records_by_shard(project_name, topic_name, shard_id, record_list) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Put records to a specific shard of a topic. ```APIDOC ## put_records_by_shard(project_name, topic_name, shard_id, record_list) ### Description Put records to a specific shard of a topic. ### Parameters - **project_name** (string) - project name - **topic_name** (string) - topic name - **shard_id** (string) - shard id - **record_list** (list) - record list ### Returns - **datahub.models.PutRecordsResult** - failed records info ``` -------------------------------- ### get_subscription_offset(project_name, topic_name, sub_id, shard_ids=None) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves the offset for a subscription. ```APIDOC ## get_subscription_offset(project_name, topic_name, sub_id, shard_ids=None) ### Description Get subscription offset. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **sub_id** (string) - Required - subscription id - **shard_ids** (list) - Optional - shard ids ### Returns - **GetSubscriptionOffsetResult** (datahub.models.results.GetSubscriptionOffsetResult) - offset info ### Exceptions - **ResourceNotFoundException** - if the project, topic or subscription does not exist - **InvalidParameterException** - if project_name, topic_name or sub_id is empty ``` -------------------------------- ### update_project Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Updates the description/comment for a project. ```APIDOC ## update_project(project_name, comment) ### Description Update project comment. ### Parameters - **project_name** - project name - **comment** - new description of project ``` -------------------------------- ### update_topic Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Updates the life cycle and comment information for an existing topic. ```APIDOC ## update_topic(project_name, topic_name, life_cycle, comment) ### Description Updates topic information. Only the life cycle and comment fields can be modified. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **life_cycle** (int) - Required - life cycle of topic - **comment** (string) - Required - topic comment ### Exceptions - **ResourceNotFoundException**: Raised if the project or topic does not exist. - **InvalidParameterException**: Raised if the project name or topic name is empty, or if life_cycle is not positive. ``` -------------------------------- ### datahub.client.ConsumerConfig Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Configuration class for the Datahub consumer, defining credentials, endpoints, and operational parameters. ```APIDOC ## class datahub.client.ConsumerConfig ### Description Configuration object used to initialize a Datahub consumer client. ### Parameters - **access_id** (string) - Required - Aliyun access id - **access_key** (string) - Required - Aliyun access key - **endpoint** (string) - Required - Datahub endpoint - **protocol_type** (DatahubProtocolType) - Optional - Protocol type for datahub client - **compress_format** (CompressFormat) - Optional - Compress format for records data - **retry_times** (int) - Optional - Retry times when request error - **async_thread_limit** (int) - Optional - Thread num limit for thread pool in message reader - **thread_queue_limit** (int) - Optional - Task num limit for queue in thread pool in message reader - **logging_level** (int) - Optional - Logging level - **logging_filename** (string) - Optional - Logging file name - **auto_ack_offset** (bool) - Optional - Auto ack offset for fetched records or not - **session_timeout** (int) - Optional - Session timeout - **max_record_buffer_size** (int) - Optional - Max record buffer size in consumer - **fetch_limit** (int) - Optional - Fetch num limit need to consume ``` -------------------------------- ### get_blob_records(project_name, topic_name, shard_id, cursor, limit_num=0, sub_id=None) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves records from a specific shard in a topic. ```APIDOC ## get_blob_records(project_name, topic_name, shard_id, cursor, limit_num=0, sub_id=None) ### Description Get records from a topic. ### Parameters - **project_name** - project name - **topic_name** - topic name - **shard_id** - shard id - **cursor** - the cursor - **limit_num** - record number need to read ### Returns - **result** (datahub.models.GetRecordsResult) - include record list, start sequence, record num and next cursor ### Exceptions - **ResourceNotFoundException**: if the project or topic or shard not exists - **InvalidParameterException**: if the cursor is invalid; project_name, topic_name, shard_id, or cursor is empty - **DatahubException**: if crc is wrong in pb mode ``` -------------------------------- ### datahub.client.DatahubConsumer Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md The main consumer client class used to interact with Datahub topics for data consumption. ```APIDOC ## class datahub.client.DatahubConsumer ### Description Consumer client for datahub used to read data from a specific project and topic. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **sub_id** (string) - Required - subscription id for consume - **consumer_config** (ConsumerConfig) - Required - config for consumer client - **shard_ids** (list) - Optional - list of string: shard list you want to consume. Default is None, means allocated automatically by datahub server - **timestamp** (int) - Optional - set the start timestamp for consume. Default is -1, means start with the subscription offset ``` -------------------------------- ### extend_shard(project_name, topic_name, shard_count) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Extends the number of shards for a topic. ```APIDOC ## extend_shard(project_name, topic_name, shard_count) ### Description Extend shard. ### Parameters - **project_name** - project name - **topic_name** - topic name - **shard_count** - shard count extend to ### Returns - **none** ``` -------------------------------- ### get_cursor(project_name, topic_name, shard_id, cursor_type, param=-1) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves a cursor for a specific shard. This cursor is required before invoking get_blob_records or get_tuple_records. ```APIDOC ## get_cursor(project_name, topic_name, shard_id, cursor_type, param=-1) ### Description Get a cursor for a specific shard. This must be invoked to obtain a cursor before calling get_blob_records or get_tuple_records. ### Parameters - **project_name** (string) - Required - project name - **topic_name** (string) - Required - topic name - **shard_id** (string) - Required - shard id - **cursor_type** (datahub.models.CursorType) - Required - cursor type - **param** (int) - Optional - system time if cursor_type == CursorType.SYSTEM_TIME, sequence if cursor_type == CursorType.SEQUENCE ### Returns - **GetCursorResult** (datahub.models.GetCursorResult) - cursor info ### Exceptions - **ResourceNotFoundException** - if the project, topic or shard does not exist - **InvalidParameterException** - if the param is invalid; project_name, topic_name or shard_id is empty; cursor_type is wrong type; param is missing ``` -------------------------------- ### get_connector_done_time(project_name, topic_name, connector_id) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves the completion time for a connector. ```APIDOC ## get_connector_done_time(project_name, topic_name, connector_id) ### Description Get connector done time. ### Parameters - **project_name** - project name - **topic_name** - topic name - **connector_id** - connector id, compatible for connector type ``` -------------------------------- ### reset_subscription_offset(project_name, topic_name, sub_id, offsets) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Update the subscription offset. ```APIDOC ## reset_subscription_offset(project_name, topic_name, sub_id, offsets) ### Description Update the subscription offset. ### Parameters - **project_name** (string) - project name - **topic_name** (string) - topic name - **sub_id** (string) - subscription id - **offsets** (dict) - offsets ``` -------------------------------- ### sync_group Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Synchronizes consumer group information, including shard release and completion status. ```APIDOC ## sync_group(project_name, topic_name, consumer_group, consumer_id, version_id, release_shard_list, read_end_shard_list) ### Description Sync consumer group info. ### Parameters - **project_name** - project name - **topic_name** - topic name - **consumer_group** - consumer group use sub_id you want to join - **consumer_id** - consumer id obtained at the time of join group - **version_id** - offset version id obtained at the time of join group - **release_shard_list** - the shard list to release - **read_end_shard_list** - the shard list have been read finished ``` -------------------------------- ### get_connector_shard_status(project_name, topic_name, connector_id, shard_id='') Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves the status of a specific connector shard. ```APIDOC ## get_connector_shard_status(project_name, topic_name, connector_id, shard_id='') ### Description Get data connector shard status. ### Parameters - **project_name** - project name - **topic_name** - topic name - **connector_id** - connector id, compatible for connector type - **shard_id** - shard id ### Returns - **data connector shard status** (datahub.models.results.GetConnectorShardStatusResult) ### Exceptions - **ResourceNotFoundException**: if the project, topic, shard or connector not exists - **InvalidParameterException**: if project_name, topic_name or shard_id is empty; connector_type is wrong type ``` -------------------------------- ### leave_group Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Leaves a consumer group. ```APIDOC ## leave_group(project_name, topic_name, consumer_group, consumer_id, version_id) ### Description Leave consumer group info. ### Parameters - **project_name** - project name - **topic_name** - topic name - **consumer_group** - consumer group use sub_id you want to join - **consumer_id** - consumer id obtained at the time of join group - **version_id** - offset version id obtained at the time of join group ``` -------------------------------- ### reload_connector(project_name, topic_name, connector_id, shard_id='') Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Reload a data connector by a given shard id or reload all shards if no shard id is provided. ```APIDOC ## reload_connector(project_name, topic_name, connector_id, shard_id='') ### Description Reload a data connector by a given shard id or reload all shards if no shard id is provided. ### Parameters - **project_name** (string) - project name - **topic_name** (string) - topic name - **connector_id** (str or datahub.models.ConnectorType) - connector id, compatible for connector type - **shard_id** (string) - shard id ``` -------------------------------- ### delete_project Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Deletes a project by its name. ```APIDOC ## delete_project(project_name) ### Description Delete the project by given name. ### Parameters - **project_name** (str) - Required - project name ``` -------------------------------- ### append_field Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Appends a field to a tuple topic. ```APIDOC ## append_field(project_name, topic_name, field_name, field_type) ### Description Appends a field to a tuple-based topic. ### Parameters - **project_name** (str) - Required - Project name - **topic_name** (str) - Required - Topic name - **field_name** (str) - Required - Name of the field to append - **field_type** (FieldType) - Required - Data type of the field ``` -------------------------------- ### update_connector Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Updates the configuration of a specific data connector. ```APIDOC ## update_connector(project_name, topic_name, connector_id, config) ### Parameters - **project_name** - project name - **topic_name** - topic name - **connector_id** - connector id, compatible for connector type - **config** - connector config ``` -------------------------------- ### get_tuple_records Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Retrieves records from a specified topic shard. ```APIDOC ## get_tuple_records(project_name, topic_name, shard_id, record_schema=None, cursor='', limit_num=0, sub_id=None) ### Description Get records from a topic. ### Parameters - **project_name** - project name - **topic_name** - topic name - **shard_id** - shard id - **record_schema** - tuple record schema - **filter** - filter - **cursor** - the cursor - **limit_num** - record number need to read ### Returns - result include record list, start sequence, record num and next cursor (datahub.models.GetRecordsResult) ``` -------------------------------- ### delete_topic(project_name, topic_name) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Deletes a specified topic within a project. ```APIDOC ## delete_topic(project_name, topic_name) ### Description Delete a topic. ### Parameters - **project_name** - project name - **topic_name** - topic name ### Returns - **none** ### Exceptions - **ResourceNotFoundException**: if the project or topic not exists - **InvalidParameterException**: if the project name or topic name is empty ``` -------------------------------- ### datahub.client.DatahubProducer Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md The primary client class for producing data to a specific Datahub topic. ```APIDOC ## class datahub.client.DatahubProducer ### Description Producer client used to write data to a specific project and topic in Datahub. ### Parameters - **project_name** (string) - Required - Project name - **topic_name** (string) - Required - Topic name - **producer_config** (ProducerConfig) - Required - Configuration object for the producer - **shard_ids** (list) - Optional - List of shard IDs to produce to. Default is None, which writes to all shards evenly. ``` -------------------------------- ### delete_topic_schema(project_name, topic_name, version_id) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Deletes a specific schema version for a topic. ```APIDOC ## delete_topic_schema(project_name, topic_name, version_id) ### Description Delete the special schema by version id of a topic. ### Parameters - **project_name** - project name - **topic_name** - topic name - **version_id** - version id ### Returns - **none** ### Exceptions - **ResourceNotFoundException**: if the project or topic not exists - **InvalidParameterException**: if project_name or topic_name is empty ``` -------------------------------- ### merge_shard(project_name, topic_name, shard_id, adj_shard_id) Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Merges two adjacent shards into one. ```APIDOC ## merge_shard(project_name, topic_name, shard_id, adj_shard_id) ### Description Merge shards. ### Parameters - **project_name** - project name - **topic_name** - topic name - **shard_id** - shard id - **adj_shard_id** - adjacent shard id ### Returns - **shards info after merged** (datahub.models.MergeShardResult) ``` -------------------------------- ### update_subscription_offset Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Updates the offset for a subscription. ```APIDOC ## update_subscription_offset(project_name, topic_name, sub_id, offsets) ### Description Update subscription offset. ### Parameters - **project_name** - project name - **topic_name** - topic name - **sub_id** - subscription id - **offsets** - offsets ``` -------------------------------- ### update_connector_state Source: https://github.com/aliyun/aliyun-datahub-sdk-python/blob/master/docs/source/api.md Updates the operational state of a data connector. ```APIDOC ## update_connector_state(project_name, topic_name, connector_id, connector_state) ### Description Update data connector state. ### Parameters - **project_name** - project name - **topic_name** - topic name - **connector_id** - connector id, compatible for connector type - **connector_state** - connector state ```