Skip to content

2. Space

Charles K. Neimog edited this page Feb 9, 2025 · 5 revisions

Description

The Space class is used to interact with and manage objects, types, and other elements within a specific Space. It provides methods to retrieve objects, types, and perform search operations within the space. Additionally, it allows creating new objects associated with specific types.

Properties

  • name: The name of the space.
  • id: The ID of the space.

Methods

get_object

Retrieves a specific object by its ID.

def get_object(self, objectId: str, offset=0, limit=100) -> Object:
  • Parameters:

    • objectId (str): The ID of the object to retrieve.
    • offset (int, optional): The offset for pagination (default: 0).
    • limit (int, optional): The limit for the number of results (default: 100).
  • Returns:

    • An Object instance representing the retrieved object.
  • Raises:

    • Raises an error if the request to the API fails.

get_objects

Retrieves a list of objects associated with the space.

def get_objects(self, offset=0, limit=100) -> list[Object]:
  • Parameters:

    • offset (int, optional): The offset for pagination (default: 0).
    • limit (int, optional): The limit for the number of results (default: 100).
  • Returns:

    • A list of Object instances.
  • Raises:

    • Raises an error if the request to the API fails.

get_members

Retrieves a list of members associated with the space.

def get_members(self, offset=0, limit=100) -> list[Member]:
  • Parameters:

    • offset (int, optional): The offset for pagination (default: 0).
    • limit (int, optional): The limit for the number of results (default: 100).
  • Returns:

    • A list of Member instances.
  • Raises:

    • Raises an error if the request to the API fails.

get_types

Retrieves a list of types associated with the space.

def get_types(self, offset=0, limit=100) -> list[Type]:
  • Parameters:

    • offset (int, optional): The offset for pagination (default: 0).
    • limit (int, optional): The limit for the number of results (default: 100).
  • Returns:

    • A list of Type instances.
  • Raises:

    • Raises an error if the request to the API fails.

get_type

Retrieves a specific type by its name.

def get_type(self, type_name: str) -> Type:
  • Parameters:

    • type_name (str): The name of the type to retrieve.
  • Returns:

    • A Type instance representing the type.
  • Raises:

    • ValueError: If the type with the specified name is not found.

search

Performs a search for objects in the space using a query string.

def search(self, query, offset=0, limit=10) -> list[Object]:
  • Parameters:

    • query (str): The search query string.
    • offset (int, optional): The offset for pagination (default: 0).
    • limit (int, optional): The limit for the number of results (default: 10).
  • Returns:

    • A list of Object instances that match the search query.
  • Raises:

    • ValueError: If the space ID is not set.

create_object

Creates a new object within the space, associated with a specified type.

def create_object(self, obj: Object, type: Type) -> Object:
  • Parameters:

    • obj (Object): The Object instance to create.
    • type (Type): The Type instance to associate the object with.
  • Returns:

    • A new Object instance representing the created object.
  • Raises:

    • Raises an error if the request to the API fails.

Example Usage

# Create a new Space instance
space = Space()

# Retrieve all objects in the space
objects = space.get_objects()

# Retrieve a specific object by ID
obj = space.get_object("object_id")

# Search for objects in the space
search_results = space.search("query")

# Retrieve all types in the space
types = space.get_types()

# Create a new object within the space
new_obj = Object()
new_obj.name = "New Object"
new_obj.icon = "📄"
type_instance = space.get_type("Page")
created_obj = space.create_object(new_obj, type_instance)

# Print the string representation of the space
print(space)  # Output: <Space(name={self.name})>
Clone this wiki locally