client
Log in to LucidLink with a service account and choose where the client keeps its local files.
Client is the entry point of the SDK: it logs in with ServiceAccountCredentials and gives access to the service account's Workspace. StorageConfig and StorageMode choose whether the client's local files (the caches and metadata of the filespaces it links) live in a temporary directory removed when the client closes, or in a directory that is kept.
lucidlink.Client
Client(*, storage: StorageConfig | None = None)Parameter | Description |
|---|---|
| Where the client keeps its local files. None is the same as StorageConfig(): a temporary directory, removed when the client closes. |
storage
Description
Where the client keeps its local files. None is the same as StorageConfig(): a temporary directory, removed when the client closes.
A connection to LucidLink for one service account.
Creating a client does no network I/O; login() authenticates it, and workspace is then the service account's workspace. Clients are independent of each other: several can run in one process, each logged in with its own service account. Use it as a context manager, or call close() when done.
Clients see each other's changes only eventually. For example, after one client closes a file, another can find it missing, empty or truncated for a few seconds; two clients creating the same new directory conflict, and one of the directories ends up as <name>_conflicted. Filespace.sync() does not by itself make changes visible to another client at once.
Use StorageMode.EPHEMERAL whenever more than one client is involved: it gives each client its own temporary directory. Clients must not share local files, so each StorageMode.PERSISTENT client needs a root_path of its own.
A Client is not thread safe: do not use it, or the objects obtained from it, from several threads at the same time. In a process forked while a client is running, every LucidLink call raises ClientError; start worker processes with the spawn or forkserver start method instead.
After close() the client is closed for good: login(), workspace and the operations of the objects obtained through it (Workspace, Filespace, FileSystem, FsUtils and the Connect objects) raise ClientClosedError; Filespace.unlink() and leaving a filespace's with block do nothing. The files opened through it were closed by close() and raise the ValueError of a closed file. Create a new Client for further work.
Raises
Exception | Condition |
|---|---|
If the storage configuration is rejected. |
Client example
from lucidlink import Client, ServiceAccountCredentialswith Client() as client:client.login(ServiceAccountCredentials("sa_live:..."))with client.workspace.link_filespace("fs-uuid-12345") as filespace:print(filespace.file_system.read_dir("/"))# Leaving the blocks unlinked the filespace and closed the client
workspace: Workspace
The workspace of the service account the client logged in as.
A service account belongs to one workspace, so a client has exactly one.
Raises
Exception | Condition |
|---|---|
If the client is not logged in. |
close() -> None
Close the client: unlink every filespace and remove the temporary directory of StorageMode.EPHEMERAL.
Each filespace is unlinked as by Filespace.unlink(): the files still open through it are closed, which writes the data they buffered, and the final sync runs if its sync_barrier asks for it. Every step runs even when an earlier one fails, and the failures are raised together afterwards. Calling close() again does nothing.
Call Filespace.sync() before closing when changes must be saved: changes a failed final sync left unsynced are lost with StorageMode.EPHEMERAL.
Raises
Exception | Condition |
|---|---|
If unlinking a filespace or stopping the local client failed; the client is closed all the same. Each failure is a member: a failed final sync is a FilespaceSyncError and a failed close of an open file a FilespaceError, which carry the filespace_id of their filespace. |
Condition
If unlinking a filespace or stopping the local client failed; the client is closed all the same. Each failure is a member: a failed final sync is a FilespaceSyncError and a failed close of an open file a FilespaceError, which carry the filespace_id of their filespace.
login(credentials: ServiceAccountCredentials) -> None
Log in to LucidLink as a service account.
Logging in again with the same token does nothing; to log in as another service account, use another Client.
Parameters
Parameter | Description |
|---|---|
| The service account to log in as. |
credentials
Description
The service account to log in as.
Raises
Exception | Condition |
|---|---|
If the token is invalid, expired or revoked. | |
If the service account is not allowed into its workspace. | |
If LucidLink services report too many requests. | |
If the client is already logged in with another token. |
lucidlink.ServiceAccountCredentials
ServiceAccountCredentials(token: str)Parameter | Description |
|---|---|
| The service account token, as copied when the service account was created, such as "sa_live:...". |
token
Description
The service account token, as copied when the service account was created, such as "sa_live:...".
The token of a service account, for Client.login().
A service account gives a program access to one workspace and to the filespaces the account has permissions for.
Raises
Exception | Condition |
|---|---|
If the token is empty, not in the format of a service account token, or contains a NUL character. |
Condition
If the token is empty, not in the format of a service account token, or contains a NUL character.
ServiceAccountCredentials example
from lucidlink import Client, ServiceAccountCredentialsclient = Client()client.login(ServiceAccountCredentials("sa_live:..."))
lucidlink.StorageConfig
Where a Client keeps its local files: the caches and metadata of the filespaces it links.
Pass it as Client(storage=...). Clients must not share local files, so each StorageMode.PERSISTENT client needs its own root_path. With StorageMode.PERSISTENT, the maximum cache sizes given to Workspace.link_filespace() are also kept when the filespace is linked again (see CacheConfig). See "Choose where the client stores data" in the Getting started guide.
Parameters
Parameter | Description |
|---|---|
| StorageMode.EPHEMERAL for a new temporary directory, removed when the client closes; StorageMode.PERSISTENT for a .lucid directory under root_path, kept when the client closes. |
| The directory under which a StorageMode.PERSISTENT client keeps its .lucid directory. Required for StorageMode.PERSISTENT, and must be None for StorageMode.EPHEMERAL. |
mode
Description
StorageMode.EPHEMERAL for a new temporary directory, removed when the client closes; StorageMode.PERSISTENT for a .lucid directory under root_path, kept when the client closes.
root_path
Description
The directory under which a StorageMode.PERSISTENT client keeps its .lucid directory. Required for StorageMode.PERSISTENT, and must be None for StorageMode.EPHEMERAL.
Raises
Exception | Condition |
|---|---|
If root_path is missing for StorageMode.PERSISTENT or given for StorageMode.EPHEMERAL. |
Condition
If root_path is missing for StorageMode.PERSISTENT or given for StorageMode.EPHEMERAL.
StorageConfig example
from pathlib import Pathfrom lucidlink import Client, StorageConfig, StorageMode# Keep the local files in ~/myapp/.lucidstorage = StorageConfig(mode=StorageMode.PERSISTENT, root_path=Path.home() / "myapp")client = Client(storage=storage)
Attribute | Type | Description |
|---|---|---|
| Whether the local files are kept after the client closes. | |
|
| The directory that holds the .lucid directory of StorageMode.PERSISTENT; None for StorageMode.EPHEMERAL. |
root_path
Type
Path | NoneDescription
The directory that holds the .lucid directory of StorageMode.PERSISTENT; None for StorageMode.EPHEMERAL.
lucidlink.StorageMode
Whether a client's local files are kept after it closes.
Member | Value | Description |
|---|---|---|
|
| In a .lucid directory under StorageConfig.root_path, kept when the client closes. |
|
| In a new temporary directory, removed when the client closes. |
PERSISTENT
Value
'persistent'Description
In a .lucid directory under StorageConfig.root_path, kept when the client closes.
EPHEMERAL
Value
'ephemeral'Description
In a new temporary directory, removed when the client closes.