### Install aioetcd3 via pip Source: https://github.com/gaopeiliang/aioetcd3/blob/master/README.md Standard installation command for the aioetcd3 library using the Python package manager. ```bash pip install aioetcd3 ``` -------------------------------- ### Watch Key Scope with Context Manager (Python) Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Demonstrates how to use the `watch_scope` context manager to efficiently watch for changes within a specified key prefix. It handles automatic reconnection and batching of events. This example requires an etcd client connection. ```Python async def watch_scope_example(): etcd = client(endpoint="127.0.0.1:2379") async with etcd.watch_scope( range_prefix('/events/'), always_reconnect=True, # Auto-reconnect on failure ignore_compact=True, # Ignore compaction errors batch_events=True # Receive events in batches ) as watch: async for events in watch: for event in events: print(f"{event.type}: {event.key.decode()}") break etcd.close() asyncio.run(watch_scope_example()) ``` -------------------------------- ### Perform Key-Value Get Operation with aioetcd3 Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Shows how to retrieve a single key's value and metadata from etcd using the `get()` method. Includes fetching the latest value and metadata, and retrieving historical values by specifying a revision number. ```python from aioetcd3.client import client import asyncio async def get_example(): etcd = client(endpoint="127.0.0.1:2379") # Basic get operation value, meta = await etcd.get('/config/database/host') if value: print(f"Value: {value.decode()}") print(f"Create revision: {meta.create_revision}") print(f"Mod revision: {meta.mod_revision}") print(f"Version: {meta.version}") else: print("Key not found") # Get with specific revision (historical value) value, meta = await etcd.get('/config/database/host', revision=100) etcd.close() asyncio.run(get_example()) ``` -------------------------------- ### Lease Management and TTL Operations Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Covers granting, refreshing, and revoking leases to manage key expiration. Includes a context manager example for automatic lease maintenance. ```python from aioetcd3.client import client import asyncio async def lease_example(): etcd = client(endpoint="127.0.0.1:2379") lease = await etcd.grant_lease(ttl=30) await etcd.put('/services/worker1', 'active', lease=lease) refreshed_lease = await etcd.refresh_lease(lease) lease_info, keys = await etcd.get_lease_info(lease) await etcd.revoke_lease(lease) etcd.close() async def lease_scope_example(): etcd = client(endpoint="127.0.0.1:2379") async with etcd.grant_lease_scope(ttl=60) as lease: await etcd.put('/services/my_service', 'running', lease=lease) await asyncio.sleep(30) etcd.close() ``` -------------------------------- ### Perform CRUD and Transactional Operations with aioetcd3 Source: https://github.com/gaopeiliang/aioetcd3/blob/master/README.md Demonstrates core etcd operations including putting, getting, listing, and deleting keys. It also covers advanced features like lease management and atomic transactions. ```python from aioetcd3.client import client from aioetcd3.help import range_all from aioetcd3.kv import KV from aioetcd3 import transaction etcd_client = client(endpoints="127.0.0.1:2379") await etcd_client.put('/foo', 'foo') value, meta = await etcd_client.get('/foo') value_list = await etcd_client.range(range_all()) await etcd_client.delete('/foo') lease = await etcd_client.grant_lease(ttl=5) await etcd_client.put('/foo1', 'foo', lease=lease) is_success, response = await etcd_client.txn(compare=[ transaction.Value('/trans1') == b'trans1', transaction.Value('/trans2') == b'trans2' ], success=[ KV.delete.txn('/trans1'), KV.put.txn('/trans3', 'trans3', prev_kv=True) ], fail=[ KV.delete.txn('/trans1') ]) await etcd_client.user_add(username="test user", password='1234') await etcd_client.role_add(name="test_role") ``` -------------------------------- ### Execute Atomic Transactions (Python) Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Illustrates how to perform atomic transactions in etcd using conditional logic. Transactions can compare key values, versions, or revisions before executing success or failure branches. This example sets up initial values, attempts a conditional deduction, and handles transaction outcomes. ```Python from aioetcd3.client import client from aioetcd3.kv import KV from aioetcd3 import transaction import asyncio async def transaction_example(): etcd = client(endpoint="127.0.0.1:2379") # Setup initial values await etcd.put('/account/balance', '100') await etcd.put('/account/status', 'active') # Transaction: if balance == 100 and status == active, # then deduct 50 and update timestamp is_success, responses = await etcd.txn( compare=[ transaction.Value('/account/balance') == b'100', transaction.Value('/account/status') == b'active' ], success=[ KV.put.txn('/account/balance', '50'), KV.put.txn('/account/last_transaction', '2024-01-15'), ], fail=[ KV.get.txn('/account/balance'), # Get current balance on failure ] ) if is_success: print("Transaction succeeded") else: print("Transaction failed, current balance:", responses[0]) etcd.close() asyncio.run(transaction_example()) ``` -------------------------------- ### Manage etcd Cluster Membership Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Provides examples for listing cluster members, checking member health, and managing cluster topology. These operations are essential for maintaining high availability. ```python from aioetcd3.client import client import asyncio async def cluster_example(): etcd = client(endpoint="127.0.0.1:2379") members = await etcd.member_list() for member in members: print(f"Member ID: {member.ID}") healthy, unhealthy = await etcd.member_healthy() print(f"Healthy members: {healthy}") etcd.close() asyncio.run(cluster_example()) ``` -------------------------------- ### Manage etcd Authentication and Users Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Demonstrates how to create users, define roles with specific permissions, assign roles to users, and perform lifecycle management for credentials. It requires an active etcd client connection. ```python from aioetcd3.client import client from aioetcd3.help import range_prefix, PER_R, PER_W, PER_RW import asyncio async def auth_example(): etcd = client(endpoint="127.0.0.1:2379") await etcd.user_add(username='app_user', password='secure_password') await etcd.role_add(name='app_role') await etcd.role_grant_permission(name='app_role', key_range=range_prefix('/app/'), permission=PER_RW) await etcd.user_grant_role(username='app_user', role='app_role') users = await etcd.user_list() print(f"Users: {users}") await etcd.user_delete(username='app_user') etcd.close() asyncio.run(auth_example()) ``` -------------------------------- ### Define Key Ranges with Helper Functions Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Shows how to utilize built-in helper functions to generate key range tuples for queries, supporting prefixes, comparisons, and exclusion logic. ```python from aioetcd3.help import range_all, range_prefix # Get all keys in the keyspace all_range = range_all() # Get all keys starting with '/services/' prefix_range = range_prefix('/services/') ``` -------------------------------- ### Perform Range Queries with Comparison Operators Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Demonstrates how to fetch keys using greater than, less than, and equality comparison operators. These functions allow for flexible range selection within the etcd key space. ```python gt_range = range_greater('/config/a') gte_range = range_greater_equal('/config/a') lt_range = range_less('/config/z') lte_range = range_less_equal('/config/z') ``` -------------------------------- ### Perform Key-Value Range Operation with aioetcd3 Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Demonstrates retrieving multiple key-value pairs using the `range()` method. Supports fetching keys by prefix, across the entire keyspace, and with options for sorting, limiting results (pagination), and filtering based on key comparisons. ```python from aioetcd3.client import client from aioetcd3.help import range_all, range_prefix, range_greater, range_less import asyncio async def range_example(): etcd = client(endpoint="127.0.0.1:2379") # Get all keys with a specific prefix results = await etcd.range(range_prefix('/config/')) for key, value, meta in results: print(f"{key.decode()}: {value.decode()}") # Get all keys in the entire keyspace all_keys = await etcd.range(range_all()) # Range with sorting (ascending by key) results = await etcd.range( range_prefix('/users/'), sort_order='ascend', sort_target='key' ) # Range with descending order by modification time results = await etcd.range( range_prefix('/logs/'), sort_order='descend', sort_target='mod' ) # Range with limit (pagination) results = await etcd.range(range_prefix('/items/'), limit=10) # Get keys greater than a specific key results = await etcd.range(range_greater('/config/a')) # Get keys less than a specific key results = await etcd.range(range_less('/config/z')) etcd.close() asyncio.run(range_example()) ``` -------------------------------- ### Watch Operations for Real-time Monitoring Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Demonstrates monitoring keys for changes using the watch API, including handling create, modify, and delete events with prefix filtering. ```python from aioetcd3.client import client from aioetcd3.help import range_prefix from aioetcd3.watch import EVENT_TYPE_CREATE, EVENT_TYPE_MODIFY, EVENT_TYPE_DELETE import asyncio async def watch_example(): etcd = client(endpoint="127.0.0.1:2379") async for event in etcd.watch('/config/setting'): if event.type == EVENT_TYPE_CREATE: print("Key was created") break etcd.close() async def watch_prefix_example(): etcd = client(endpoint="127.0.0.1:2379") async for event in etcd.watch(range_prefix('/services/'), prev_kv=True): print(f"Key: {event.key.decode()}") break etcd.close() ``` -------------------------------- ### Create aioetcd3 Client Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Demonstrates how to create an etcd client connection using aioetcd3. Supports basic insecure connections, multiple endpoints for load balancing, username/password authentication, and secure SSL/TLS connections. Includes closing the connection. ```python from aioetcd3.client import client, ssl_client import asyncio # Basic insecure connection etcd_client = client(endpoint="127.0.0.1:2379", timeout=5) # Connection with multiple endpoints for load balancing etcd_client = client(endpoint="127.0.0.1:2379,127.0.0.1:2380") # Connection with username/password authentication etcd_client = client( endpoint="127.0.0.1:2379", username="root", password="secret", timeout=10 ) # SSL/TLS secure connection secure_client = ssl_client( endpoint="127.0.0.1:2379", ca_file="/path/to/ca.pem", cert_file="/path/to/client.pem", key_file="/path/to/client-key.pem", timeout=5 ) # Close connection when done etcd_client.close() ``` -------------------------------- ### Perform Key-Value Put Operation with aioetcd3 Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Illustrates how to store key-value pairs in etcd using the `put()` method. Covers simple puts, retrieving previous values, associating keys with leases for automatic expiration, and setting custom timeouts for operations. ```python from aioetcd3.client import client import asyncio async def put_example(): etcd = client(endpoint="127.0.0.1:2379") # Simple put operation await etcd.put('/config/database/host', 'localhost') # Put with previous value retrieval prev_value, prev_meta = await etcd.put('/config/database/port', '5432', prev_kv=True) if prev_value: print(f"Previous value: {prev_value.decode()}") # Put with a lease (key expires when lease expires) lease = await etcd.grant_lease(ttl=60) await etcd.put('/services/web/node1', '192.168.1.10', lease=lease) # Put with custom timeout await etcd.put('/config/timeout', '30', timeout=5) etcd.close() asyncio.run(put_example()) ``` -------------------------------- ### Range Keys and Count Operations Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Shows how to efficiently retrieve only keys within a specific range or prefix and count the number of keys matching a criteria without fetching full values. ```python from aioetcd3.client import client from aioetcd3.help import range_prefix import asyncio async def range_keys_example(): etcd = client(endpoint="127.0.0.1:2379") keys = await etcd.range_keys(range_prefix('/services/')) for key, meta in keys: print(f"Key: {key.decode()}, Version: {meta.version}") count = await etcd.count(range_prefix('/services/')) print(f"Total services: {count}") etcd.close() asyncio.run(range_keys_example()) ``` -------------------------------- ### Advanced Transaction Comparisons (Python) Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Shows advanced transaction capabilities in etcd, including comparisons based on key versions, creation revisions, and modification revisions. It also demonstrates transactions with delete and range operations in the success branch. ```Python from aioetcd3.client import client from aioetcd3.kv import KV from aioetcd3 import transaction import asyncio async def advanced_transaction_example(): etcd = client(endpoint="127.0.0.1:2379") # Compare by version (number of modifications) is_success, _ = await etcd.txn( compare=[ transaction.Version('/config/setting') > 0, # Key exists transaction.Version('/config/setting') < 10, # Modified less than 10 times ], success=[ KV.put.txn('/config/setting', 'new_value'), ], fail=[] ) # Compare by create revision is_success, _ = await etcd.txn( compare=[ transaction.Create('/lock/resource') == 0, # Key doesn't exist ], success=[ KV.put.txn('/lock/resource', 'locked'), ], fail=[] ) # Compare by modification revision is_success, _ = await etcd.txn( compare=[ transaction.Mod('/data/item') != 0, # Key has been modified ], success=[ KV.delete.txn('/data/item'), ], fail=[] ) # Transaction with delete and get in success branch is_success, responses = await etcd.txn( compare=[ transaction.Value('/queue/front') != b'', ], success=[ KV.delete.txn('/queue/front', prev_kv=True), KV.range.txn(('/queue/', '/queue0')), # Get remaining items ], fail=[] ) etcd.close() asyncio.run(advanced_transaction_example()) ``` -------------------------------- ### Delete and Pop Keys in aioetcd3 Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Demonstrates how to delete single keys, keys by prefix, and retrieve previous values using delete and pop operations. These methods return metadata and values associated with the deleted keys. ```python from aioetcd3.client import client from aioetcd3.help import range_prefix import asyncio async def delete_example(): etcd = client(endpoint="127.0.0.1:2379") deleted_count = await etcd.delete('/config/old_setting') deleted = await etcd.delete('/config/temp', prev_kv=True) for key, value, meta in deleted: print(f"Deleted: {key.decode()} = {value.decode()}") await etcd.delete(range_prefix('/temp/')) deleted = await etcd.pop('/config/feature_flag') for key, value, meta in deleted: print(f"Popped: {value.decode()}") etcd.close() asyncio.run(delete_example()) ``` -------------------------------- ### Authentication and User Management Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Manage users, roles, and permissions for etcd authentication. This includes adding users, creating roles, granting permissions, and managing user-role assignments. ```APIDOC ## Authentication and User Management Manage users, roles, and permissions for etcd authentication. ### Description This section details how to manage authentication, users, roles, and permissions within etcd using the aioetcd3 library. ### Methods - `user_add(username, password)`: Creates a new user. - `role_add(name)`: Creates a new role. - `role_grant_permission(name, key_range, permission)`: Grants a permission to a role. - `user_grant_role(username, role)`: Assigns a role to a user. - `user_list()`: Lists all users. - `user_get(username)`: Retrieves roles assigned to a user. - `role_list()`: Lists all roles. - `role_get(name)`: Retrieves permissions for a role. - `auth_enable()`: Enables authentication (requires root). - `user_change_password(username, password)`: Changes a user's password. - `user_revoke_role(username, role)`: Revokes a role from a user. - `role_revoke_permission(name, key_range)`: Revokes a permission from a role. - `role_delete(name)`: Deletes a role. - `user_delete(username)`: Deletes a user. ### Example Usage (Python) ```python from aioetcd3.client import client from aioetcd3.help import range_prefix, PER_R, PER_W, PER_RW import asyncio async def auth_example(): etcd = client(endpoint="127.0.0.1:2379") # Create a new user await etcd.user_add(username='app_user', password='secure_password') # Create a role await etcd.role_add(name='app_role') # Grant read-write permission on a key prefix to the role await etcd.role_grant_permission( name='app_role', key_range=range_prefix('/app/'), permission=PER_RW # Read-write permission ) # Grant read-only permission on config await etcd.role_grant_permission( name='app_role', key_range=range_prefix('/config/'), permission=PER_R # Read-only permission ) # Assign role to user await etcd.user_grant_role(username='app_user', role='app_role') # List all users users = await etcd.user_list() print(f"Users: {users}") # Get user's roles roles = await etcd.user_get(username='app_user') print(f"User roles: {roles}") # List all roles all_roles = await etcd.role_list() print(f"All roles: {all_roles}") # Get role permissions permissions = await etcd.role_get(name='app_role') print(f"Role permissions: {permissions}") # Enable authentication (requires root user) # await etcd.auth_enable() # Change user password await etcd.user_change_password(username='app_user', password='new_password') # Revoke role from user await etcd.user_revoke_role(username='app_user', role='app_role') # Revoke permission from role await etcd.role_revoke_permission(name='app_role', key_range=range_prefix('/config/')) # Delete role and user await etcd.role_delete(name='app_role') await etcd.user_delete(username='app_user') etcd.close() asyncio.run(auth_example()) ``` ``` -------------------------------- ### Watch Operations Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Monitor keys for real-time changes including creation, modification, and deletion events. ```APIDOC ## GET /watch ### Description Establishes a stream to watch for changes on a key or range of keys. ### Method GET ### Parameters #### Query Parameters - **key** (string) - Required - The key or prefix to monitor. - **prev_kv** (boolean) - Optional - Include previous value in event. ### Response #### Success Response (200) - **event** (object) - Contains event type (CREATE, MODIFY, DELETE), key, and value. ``` -------------------------------- ### Range Helper Functions Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Helper functions for creating key ranges for queries and operations. These functions simplify the process of defining key ranges for various etcd operations. ```APIDOC ## Range Helper Functions Helper functions for creating key ranges for queries and operations. ### Description This section provides utility functions to easily define key ranges for operations like `get`, `put`, and `delete` in etcd. These functions help in specifying exact keys, prefixes, or ranges with different comparison operators. ### Functions - `range_all()`: Returns a range covering all keys. - `range_prefix(prefix)`: Returns a range for a given prefix. - `range_greater(key)`: Returns a range for keys greater than the specified key. - `range_less(key)`: Returns a range for keys less than the specified key. - `range_greater_equal(key)`: Returns a range for keys greater than or equal to the specified key. - `range_less_equal(key)`: Returns a range for keys less than or equal to the specified key. - `range_excluding(start_key, end_key)`: Returns a range excluding the start and end keys. - `range_prefix_excluding(prefix)`: Returns a range for a prefix, excluding keys that exactly match the prefix. ### Sorting Options - `SORT_ASCEND`: Sort keys in ascending order. - `SORT_DESCEND`: Sort keys in descending order. ### Example Usage (Python) ```python from aioetcd3.help import ( range_all, range_prefix, range_greater, range_less, range_greater_equal, range_less_equal, range_excluding, range_prefix_excluding, SORT_ASCEND, SORT_DESCEND ) # Get all keys in the keyspace all_range = range_all() # Returns (b'\x00', b'\x00') # Get all keys starting with '/services/' prefix_range = range_prefix('/services/') # Returns ('/services/', '/services0') ``` ``` -------------------------------- ### Filter Ranges with Exclusions Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Shows how to retrieve ranges while explicitly excluding specific keys or sub-ranges. This is useful for filtering out deprecated or test keys from a broader prefix search. ```python excluded_range = range_prefix_excluding(prefix='/services/', with_out=['/services/deprecated', '/services/test']) excluded = range_excluding(range_=('/a', '/z'), with_out=['/internal', ('/temp/', '/temp0')]) ``` -------------------------------- ### Lease Management Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Manage TTL-based leases to automatically expire keys after a set duration. ```APIDOC ## POST /lease/grant ### Description Creates a new lease with a specific Time-To-Live (TTL). ### Method POST ### Parameters #### Request Body - **ttl** (integer) - Required - Time in seconds for the lease. ### Response #### Success Response (200) - **lease_id** (string) - Unique identifier for the lease. ``` -------------------------------- ### Access Sorting Constants Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Displays the constants used to define the sort order for range query results. ```python print(SORT_ASCEND) print(SORT_DESCEND) ``` -------------------------------- ### Range Keys Operation Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Efficiently retrieve or count keys within a specific range or prefix without fetching full values. ```APIDOC ## GET /keys/range ### Description Retrieves a list of keys or counts keys matching a specific range or prefix. ### Method GET ### Parameters #### Query Parameters - **range_prefix** (string) - Required - The prefix to filter keys by. ### Response #### Success Response (200) - **keys** (list) - List of key metadata objects. ``` -------------------------------- ### Perform etcd Maintenance Operations Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Covers administrative maintenance tasks including checking database status, defragmentation, history compaction, and snapshot creation for backups. ```python from aioetcd3.client import client from aioetcd3.help import ALARM_ACTION_GET, ALARM_TYPE_NONE import asyncio async def maintenance_example(): etcd = client(endpoint="127.0.0.1:2379") status = await etcd.status() print(f"Database size: {status.dbSize} bytes") await etcd.defragment() await etcd.compact(revision=1000, physical=True) remaining_bytes, blob = await etcd.snapshot() etcd.close() asyncio.run(maintenance_example()) ``` -------------------------------- ### Key-Value Delete Operations Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Methods for removing keys from etcd, including prefix-based deletion, previous value retrieval, and pop operations. ```APIDOC ## DELETE /keys ### Description Removes keys from the etcd store. Supports single key deletion, prefix-based range deletion, and returning the previous value of deleted keys. ### Method DELETE ### Parameters #### Request Body - **key** (string) - Required - The key or range prefix to delete. - **prev_kv** (boolean) - Optional - If true, returns the previous key-value pair. ### Response #### Success Response (200) - **deleted_count** (integer) - Number of keys deleted. - **deleted_data** (list) - List of deleted key-value pairs if prev_kv is enabled. ``` -------------------------------- ### Cluster Management Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Manage etcd cluster membership and monitor cluster health. This includes listing members, checking health, and performing administrative actions. ```APIDOC ## Cluster Management Manage etcd cluster membership and monitor cluster health. ### Description This section covers operations related to managing the etcd cluster, including viewing member information, checking health status, and performing administrative tasks like adding or removing members. ### Methods - `member_list()`: Lists all members in the cluster. - `member_healthy()`: Checks the health status of cluster members. - `member_add(peerurls)`: Adds a new member to the cluster. - `member_update(mid, peerurls)`: Updates the peer URLs of an existing member. - `member_remove(mid)`: Removes a member from the cluster. ### Example Usage (Python) ```python from aioetcd3.client import client import asyncio async def cluster_example(): etcd = client(endpoint="127.0.0.1:2379") # List all cluster members members = await etcd.member_list() for member in members: print(f"Member ID: {member.ID}") print(f"Name: {member.name}") print(f"Peer URLs: {member.peerURLs}") print(f"Client URLs: {member.clientURLs}") print("---") # Check cluster health healthy, unhealthy = await etcd.member_healthy() print(f"Healthy members: {healthy}") print(f"Unhealthy members: {unhealthy}") # Add a new member to the cluster # new_member = await etcd.member_add(peerurls=['http://10.0.0.4:2380']) # Update member peer URLs # await etcd.member_update(mid=member_id, peerurls=['http://10.0.0.4:2381']) # Remove a member from the cluster # remaining = await etcd.member_remove(mid=member_id) etcd.close() asyncio.run(cluster_example()) ``` ``` -------------------------------- ### Maintenance Operations Source: https://context7.com/gaopeiliang/aioetcd3/llms.txt Perform maintenance tasks like status checks, defragmentation, and snapshots. This section covers essential operations for maintaining the etcd cluster's health and integrity. ```APIDOC ## Maintenance Operations Perform maintenance tasks like status checks, defragmentation, and snapshots. ### Description This section outlines key maintenance operations for the etcd cluster, including retrieving status information, managing database size, and creating backups. ### Methods - `status()`: Retrieves the current status of the etcd cluster. - `hash()`: Computes the hash of the etcd database. - `alarm(action, type)`: Manages alarms within the cluster. - `defragment()`: Defragments the etcd database to reclaim storage space. - `compact(revision, physical)`: Compacts the etcd key-value history. - `snapshot()`: Creates a snapshot of the etcd database. ### Example Usage (Python) ```python from aioetcd3.client import client from aioetcd3.help import ALARM_ACTION_GET, ALARM_TYPE_NONE import asyncio async def maintenance_example(): etcd = client(endpoint="127.0.0.1:2379") # Get cluster status status = await etcd.status() print(f"etcd version: {status.version}") print(f"Database size: {status.dbSize} bytes") print(f"Leader ID: {status.leader}") print(f"Raft index: {status.raftIndex}") print(f"Raft term: {status.raftTerm}") # Get hash of the database db_hash = await etcd.hash() print(f"Database hash: {db_hash}") # Check for alarms alarms = await etcd.alarm(action=ALARM_ACTION_GET, type=ALARM_TYPE_NONE) for alarm in alarms: print(f"Alarm: {alarm}") # Defragment the database (reclaim storage space) await etcd.defragment() print("Defragmentation completed") # Compact the key-value history up to a specific revision await etcd.compact(revision=1000, physical=True) print("Compaction completed") # Create a snapshot remaining_bytes, blob = await etcd.snapshot() print(f"Snapshot remaining bytes: {remaining_bytes}") # Save blob to file for backup etcd.close() asyncio.run(maintenance_example()) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.