What you’ll learn
In this guide, you’ll learn how to:- Associate resources (Spaces, Sessions, Disks, Skills) with user identifiers
- Filter resources by user
- Delete a user and cascade delete all associated resources
- Build multi-tenant applications with per-user resource isolation
Prerequisites
Before you begin, ensure you have:- An Acontext API key from Acontext Dashboard, or local deployment
Initialize the client
First, create a client instance with your API key and base URL.Step-by-step tutorial
1
Create resources with user association
Associate resources with a user by passing the
user parameter when creating them. User records are created automatically when first referenced.The
user parameter is optional. Resources created without a user parameter are not associated with any user and can still be queried and managed normally.2
Filter resources by user
All list operations support filtering by user identifier to retrieve only resources belonging to a specific user.
Use user filtering to build user-specific dashboards and views.
3
Delete a user and all resources
Deleting a user removes the user record and cascades to delete all associated resources (Spaces, Sessions, Disks, and Skills).
Complete example
Here’s a complete working example that demonstrates the full workflow:Use cases
Multi-tenant Applications
Manage resources for multiple users in a single Acontext project without requiring separate API keys for each user.
Per-user Isolation
Query and manage resources for specific users, enabling user-specific dashboards and access control.
User Offboarding
Easily clean up all resources when a user leaves by deleting the user and cascading to all associated resources.
Usage Analytics
Track resource usage per user for billing, quotas, or analytics purposes.
How it works
Automatic user creation
Automatic user creation
When you create a resource with a
user parameter:- Acontext checks if a user with that identifier exists in the project
- If the user doesn’t exist, it creates a new user record automatically
- The resource is associated with the user via a foreign key
- If the user already exists, the existing user record is used
User identifiers
User identifiers
User identifiers are:
- Strings: Any string value (e.g., email addresses, user IDs, usernames)
- Unique per project: The same identifier can be used in different projects
- Case-sensitive:
[email protected]and[email protected]are different users
Cascade deletion
Cascade deletion
When you delete a user, the database’s foreign key constraints ensure that all associated resources are automatically deleted:
- All Spaces associated with the user
- All Sessions associated with the user
- All Disks associated with the user
- All Skills associated with the user
ON DELETE CASCADE constraint, ensuring data consistency.Async/await in Python
Async/await in Python
The Python SDK includes full async support for non-blocking operations:
Best practices
Always inform users before deleting their data. The cascade deletion removes all associated resources permanently.
API Reference
Delete User
For details on creating and listing resources with user parameters, see the API reference for:Troubleshooting
User not found when listing resources
User not found when listing resources
Problem: Resources exist but are not returned when filtering by user.Solution:
- Verify the user identifier is spelled correctly (case-sensitive)
- Ensure resources were created with the same user identifier
- Check that you’re querying within the same project
Cannot delete user
Cannot delete user
Problem: Getting an error when trying to delete a user.Solution:
- Verify the user identifier exists
- Ensure you have the correct API key with permissions
- URL-encode special characters in the identifier (e.g.,
@becomes%40)
Resources created without user association
Resources created without user association
Problem: Resources were created but not associated with a user.Solution:
- The
userparameter must be provided at resource creation time - Resources cannot be retroactively associated with a user
- Create new resources with the
userparameter