or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

collection-operations.mdconnection-management.mdexception-handling.mdindex.mditem-management.mdsearch-operations.md

connection-management.mddocs/

0

# Connection Management

1

2

Manages D-Bus connections to the Secret Service daemon, providing connection initialization, service availability checking, and proper connection lifecycle management.

3

4

## Capabilities

5

6

### D-Bus Connection Initialization

7

8

Creates a new D-Bus connection to the session bus for communicating with the Secret Service daemon. This connection is required for all SecretStorage operations.

9

10

```python { .api }

11

def dbus_init() -> DBusConnection:

12

"""

13

Returns a new connection to the session bus.

14

15

Returns:

16

DBusConnection: Active D-Bus connection instance

17

18

Raises:

19

SecretServiceNotAvailableException: If D-Bus session bus is unavailable

20

or environment variables are not set

21

"""

22

```

23

24

**Usage Example:**

25

```python

26

import secretstorage

27

from contextlib import closing

28

29

# Create connection (must be closed manually)

30

connection = secretstorage.dbus_init()

31

try:

32

# Use connection for operations

33

collection = secretstorage.get_default_collection(connection)

34

finally:

35

connection.close()

36

37

# Or use with context manager

38

with closing(secretstorage.dbus_init()) as connection:

39

collection = secretstorage.get_default_collection(connection)

40

# Connection automatically closed when exiting context

41

```

42

43

### Service Availability Check

44

45

Verifies whether the Secret Service daemon is running or available for activation, allowing applications to gracefully handle systems without secret service support.

46

47

```python { .api }

48

def check_service_availability(connection: DBusConnection) -> bool:

49

"""

50

Returns True if Secret Service daemon is either running or available for activation.

51

52

Parameters:

53

connection (DBusConnection): Active D-Bus connection

54

55

Returns:

56

bool: True if service is available, False otherwise

57

"""

58

```

59

60

**Usage Example:**

61

```python

62

import secretstorage

63

64

connection = secretstorage.dbus_init()

65

if secretstorage.check_service_availability(connection):

66

# Safe to use secret service operations

67

collection = secretstorage.get_default_collection(connection)

68

else:

69

# Handle case where secret service is not available

70

print("Secret service not available, using alternative storage")

71

```

72

73

## Types

74

75

```python { .api }

76

# From jeepney.io.blocking (external dependency)

77

class DBusConnection:

78

"""D-Bus connection for communicating with system services."""

79

def close(self) -> None:

80

"""Close the D-Bus connection."""

81

```