Workspaces¶
The Workspaces resource provides methods to create, retrieve, update, and delete workspaces.
Initialization¶
List Workspaces¶
Retrieve a paginated list of workspaces.
Method¶
Parameters¶
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
page |
int |
No | 1 |
Page number for pagination |
Returns¶
PaginatedWorkspaces object containing:
data: List ofWorkspaceobjectspage: Current page numbertotal_pages: Total number of pages
Example¶
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Get first page of workspaces
workspaces = client.workspaces.all(page=1)
print(f"Page {workspaces.page} of {workspaces.total_pages}")
for workspace in workspaces.data:
print(f"Workspace: {workspace.name} (ID: {workspace.id})")
Iteration Support¶
The workspaces resource supports automatic pagination through iteration:
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Iterate through all workspaces automatically
for workspace in client.workspaces:
print(f"Workspace: {workspace.name}")
print(f" Forms: {workspace.form_count}")
Official Reference¶
Create Workspace¶
Create a new workspace.
Method¶
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
str |
Yes | The workspace name |
Returns¶
Created Workspace object.
Example¶
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Create a new workspace
workspace = client.workspaces.create(name="Marketing Team")
print(f"Created workspace: {workspace.name}")
print(f"Workspace ID: {workspace.id}")
Errors¶
| Exception | Status Code | Description |
|---|---|---|
BadRequestError |
400 | Invalid workspace name |
Official Reference¶
Get Workspace¶
Retrieve a specific workspace by ID.
Method¶
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
workspace_id |
str |
Yes | The workspace ID |
Returns¶
Workspace object.
Example¶
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Get a specific workspace
workspace = client.workspaces.get(workspace_id="wksp_abc123")
print(f"Workspace: {workspace.name}")
print(f"Forms: {workspace.form_count}")
print(f"Created: {workspace.created_at}")
Errors¶
| Exception | Status Code | Description |
|---|---|---|
NotFoundError |
404 | Workspace not found |
Official Reference¶
Update Workspace¶
Update a workspace's name.
Method¶
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
workspace_id |
str |
Yes | The workspace ID |
name |
str |
Yes | The new workspace name |
Returns¶
None (successful update returns no content)
Example¶
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Update workspace name
client.workspaces.update(
workspace_id="wksp_abc123",
name="Marketing & Sales Team"
)
print("Workspace updated successfully")
Errors¶
| Exception | Status Code | Description |
|---|---|---|
NotFoundError |
404 | Workspace not found |
BadRequestError |
400 | Invalid workspace name |
Official Reference¶
Delete Workspace¶
Delete a workspace permanently.
Method¶
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
workspace_id |
str |
Yes | The workspace ID |
Returns¶
None (successful deletion returns no content)
Example¶
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Delete a workspace
client.workspaces.delete(workspace_id="wksp_abc123")
print("Workspace deleted successfully")
Errors¶
| Exception | Status Code | Description |
|---|---|---|
NotFoundError |
404 | Workspace not found |
Permanent Deletion
Deleting a workspace is permanent and cannot be undone. All forms in the workspace will also be deleted.
Official Reference¶
Models¶
Workspace Model¶
Workspace
dataclass
¶
Represents a Tally workspace.
Example:
Workspace(
id="wksp_abc123",
name="Marketing Team",
form_count=15,
created_at="2024-01-15T10:30:00Z"
)
PaginatedWorkspaces Model¶
PaginatedWorkspaces
dataclass
¶
Represents a paginated response of workspaces.
Example:
Complete Example¶
from tally import Tally, NotFoundError, BadRequestError
client = Tally(api_key="tly_your_api_key_here")
# Create a new workspace
try:
workspace = client.workspaces.create(name="Product Team")
print(f"Created: {workspace.name} (ID: {workspace.id})")
except BadRequestError as e:
print(f"Failed to create workspace: {e.message}")
# List all workspaces
print("\nAll workspaces:")
for workspace in client.workspaces:
print(f" - {workspace.name}: {workspace.form_count} forms")
# Get specific workspace
try:
workspace = client.workspaces.get(workspace_id="wksp_abc123")
print(f"\nWorkspace details:")
print(f" Name: {workspace.name}")
print(f" Forms: {workspace.form_count}")
print(f" Created: {workspace.created_at}")
except NotFoundError:
print("Workspace not found")
# Update workspace
try:
client.workspaces.update(
workspace_id="wksp_abc123",
name="Product & Engineering Team"
)
print("\nWorkspace updated successfully")
except NotFoundError:
print("Workspace not found")
# Delete workspace (use with caution!)
try:
client.workspaces.delete(workspace_id="wksp_old123")
print("\nWorkspace deleted")
except NotFoundError:
print("Workspace not found")
Use Cases¶
Organize Forms by Department¶
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Create workspaces for different departments
departments = ["Sales", "Marketing", "Support", "HR"]
for dept in departments:
workspace = client.workspaces.create(name=f"{dept} Team")
print(f"Created workspace for {dept}: {workspace.id}")
Audit Workspace Usage¶
from tally import Tally
client = Tally(api_key="tly_your_api_key_here")
# Get statistics on workspace usage
total_forms = 0
workspaces_data = []
for workspace in client.workspaces:
total_forms += workspace.form_count
workspaces_data.append({
"name": workspace.name,
"forms": workspace.form_count
})
print(f"Total workspaces: {len(workspaces_data)}")
print(f"Total forms: {total_forms}")
print("\nWorkspace breakdown:")
for ws in sorted(workspaces_data, key=lambda x: x["forms"], reverse=True):
print(f" {ws['name']}: {ws['forms']} forms")