jetraw.space module¶
Space management for Jetraw.
Spaces are top-level entities in the Jetraw platform that serve as containers for files and folders. They are associated with one or multiple storages and support permission management at the space level.
- class jetraw.space.Permission(user, space, created_at)¶
Bases:
objectRepresents a user’s permission to access a space.
- property created_at: datetime¶
- revoke()¶
Revoke the permission.
- Return type:
None
- property space_id: str¶
- property user_id: str¶
- class jetraw.space.Space(space, *, client=None)¶
Bases:
PathRepresents a Jetraw space.
Spaces are top-level containers for files and folders. They are associated with one or multiple storages and support permission management. Files and folders can be uploaded to spaces, and access can be controlled at the space level.
Example
>>> # Create a new space >>> storages = [get_storage("storage-id")] >>> space = create_space("my-space", "My Project Space", storages) >>> >>> # Grant permissions to users >>> user = get_user("user-id") >>> space.grant_permission(user) >>> >>> # List space permissions >>> for perm in space.list_permissions(): ... print(f"{perm.user.name}: {perm.added_at}")
- copy_to(destination)¶
Copy this path to a destination.
- Parameters:
destination (
PathLike) – Target path for the copy operation- Returns:
The destination path
- Return type:
Example
>>> source = Path("/my-space/image.tiff") >>> copy = source.copy_to("/my-space/backup.tiff")
- property created_at¶
Get the timestamp when the space was created.
- property display_name¶
Get the space display name.
- grant_permission(user)¶
Grant access permission to user(s) for this space.
Example
>>> # Grant permission to a single user >>> user = get_user("user-id") >>> space.grant_permission(user) >>> >>> # Grant permission to multiple users >>> users = [get_user("user1"), get_user("user2")] >>> space.grant_permission(users)
- list_permissions(batch_size=100)¶
List all users who have permission to access this space.
- Yields:
Permission – Permission objects containing user and timestamp
- Return type:
Generator[Permission,None,None]
Example
>>> # List all space permissions >>> for perm in space.list_permissions(): ... print(f"{perm.user.name}: granted at {perm.added_at}")
- move_to(destination)¶
Move this path to a destination.
- Parameters:
destination (
PathLike) – Target path for the move operation- Returns:
The destination path
- Return type:
Example
>>> source = Path("/my-space/old-name.tiff") >>> dest = source.move_to("/my-space/new-name.tiff")
- property name: str¶
Get the space name.
- property owner_id: str¶
Get the ID of the owner of the space.
- remove()¶
Delete this space.
- Return type:
None
- rename(*, name=None, display_name=None)¶
Update the space.
- revoke_permission(user)¶
Revoke access permission from user(s) for this space.
- Parameters:
user (
Union[User,str,list[Union[User,str]]]) – User object(s) to revoke permission from
Example
>>> # Revoke permission from a single user >>> user = get_user("user-id") >>> space.revoke_permission(user) >>> >>> # Revoke permission from multiple users >>> users = [get_user("user1"), get_user("user2")] >>> space.revoke_permission(users)
- property storage_ids: list[str]¶
Get the list of storage IDs associated with this space.
- unlink()¶
Delete this space. Alias for remove().
- Return type:
None
- property updated_at¶
Get the timestamp when the space was last updated.
- jetraw.space.create_space(name, storages, *, display_name=None, client=None)¶
Create a new space.
- Parameters:
- Returns:
The created space
- Return type:
- Raises:
ValueError – If parameters are invalid
Example
>>> # Create a space with associated storages >>> storages = [get_storage("storage-id-1"), get_storage("storage-id-2")] >>> space = create_space("project-alpha", "Alpha Project", storages) >>> print(f"Created space: {space.name}")
- jetraw.space.get_space(name, *, client=None)¶
Get a space by name.
- Parameters:
name (
str) – Name of the space to retrieveclient (
Optional[Client]) – Jetraw client instance (uses default if None)
- Returns:
The space object
- Return type:
- Raises:
KeyError – If the space is not found
Example
>>> space = get_space("my-project") >>> print(f"Space: {space.display_name}")
- jetraw.space.list_spaces(batch_size=100, *, client=None)¶
List all spaces accessible to the current user.
- Parameters:
client (
Optional[Client]) – Jetraw client instance (uses default if None)- Returns:
Generator of all accessible spaces
- Return type:
Generator[Space, None, None]
Example
>>> # List all spaces >>> spaces = list_spaces() >>> for space in spaces: ... print(f"{space.name}: {space.display_name}")