# Managing projects

https://virtx.sh/docs/tutorials/projects/

Group what you keep on a server into projects, share them with your team, and clean them up together.

A **project** is how you organize what you keep on a server.
Everything you create there belongs to a project.

Use projects to:

- Keep separate work apart, such as one project per app, customer, or environment.
- Share resources with teammates by adding them to a project.
- Clean up everything for one piece of work at once by removing its project.

You do not need a project to get started.
Until you choose one, everything goes into your own project, `default`.

## Create a project

**Python**

```python
project = await client.create_project("demo")
```

**Node.js**

```js
const project = await client.createProject('demo')
```

**Rust**

```rust
let project = client.create_project("demo").await?;
```

You become the project's owner.
A project name is at most 128 characters of lower-case letters, digits, `.`, `_` and `-`, not starting with `.` or `-`.
It cannot be `default`, which is your own, or be spelled like a project `id`.

To see your projects, use `list_project`, which includes those others have shared with you.
To look one up, use `get_project`.

## Work in a project

Choose the project when you connect. Everything you do through that client then happens in that project.

**Python**

```python
client = Client.connect("https://virtx.example", auth, project="demo")

volume = await client.create_volume("data")  # a volume in "demo"
```

**Node.js**

```js
const client = Client.connect('https://virtx.example', auth, 'demo')

const volume = await client.createVolume('data') // a volume in "demo"
```

**Rust**

```rust
let client = Client::connect("https://virtx.example", auth, Some("demo"))?;

let volume = client.create_volume(Some("data")).await?; // a volume in "demo"
```

To switch projects on a client you already have, use `set_project`.
In the `virtx` command, use `--project`; see [CLI](https://virtx.sh/docs/reference/cli/#which-server).

Projects are isolated from each other. A volume named `data` in one project and a volume named `data` in another are two different volumes.

## Share a project

Add teammates to a project so they can use what is in it.
Name them as the server knows them, usually by email address.

**Python**

```python
from virtx import Role

await project.set_member("bob@example.com", Role.MEMBER)
```

**Node.js**

```js
await project.setMember('bob@example.com', 'member')
```

**Rust**

```rust
use virtx::Role;

project.set_member("bob@example.com", Role::Member).await?;
```

There are two roles:

- A **member** can use everything in the project.
- An **owner** can also add and remove members, and remove the project.

`members` lists who is in a project, and `remove_member` takes someone out.
A member can also leave a project on their own with `remove_member`.

A project name is unique only for its owner, so two people can each have a project called `demo`. Your teammates must therefore use a shared project's `id`, not its name. Send them `project.id`.

Where you can share projects depends on the server:

- **Your own server:** share projects with `set_member`, as above. See [Running your own server](https://virtx.sh/docs/tutorials/self-hosting/).
- **Local server (`Client.spawn()`):** has only one user, you, so there is no one to share with.
- **VirtX cloud:** create projects and add members in the console.

## Remove a project

When the work is done, remove the project to delete everything in it at once.
Remove its sandboxes first: removing a project that still has a sandbox fails with `409`.

**Python**

```python
await project.remove()
```

**Node.js**

```js
await project.remove()
```

**Rust**

```rust
project.remove().await?;
```

You can remove your `default` project like any other. The server creates a new, empty `default` the next time you use it.
The new `default` has a new `id` and only you as a member, so you need to add your teammates again.

For every call and what each returns, see [Projects](https://virtx.sh/docs/sdk/projects/) in the SDK reference.

## Troubleshooting

1. **`400`, `invalid`, `"default" is each user's own project, made for them`**

   **Cause:** A project named `default` was created.

   **Fix:** Pick another name: everyone has a `default` already.

2. **`400`, `invalid`, `… is not a project's name`**

   **Cause:** Upper case, another character, more than 128, or a name shaped like an id.

   **Fix:** Use lower-case letters, digits, `.`, `_` and `-`, not starting with `.` or `-`.

3. **`409`, `exists`, `a project named … is already its owner's`**

   **Cause:** You already own a project with that name.

   **Fix:** Use it, or pick another name.

4. **`403`, `not a member of the project, or not from here`**

   **Cause:** A teammate's project named by its name, which finds only your own, or a project you are not in.

   **Fix:** Name it by its `id`, or ask its owner to add you.

5. **`403`, `only an owner …`**

   **Cause:** A member tried what only an owner may do.

   **Fix:** Ask an owner.

6. **`409`, `in_use`, `project … would be left without its owner`**

   **Cause:** The user whose project it is tried to leave it or step down. Other owners can leave or step down freely.

   **Fix:** Remove the project instead.

7. **`409`, `in_use`, `a sandbox lives in project …`**

   **Cause:** The project was removed while it has a sandbox.

   **Fix:** Remove its sandboxes first.

8. **`404`, from `members` or `set_member`**

   **Cause:** The server started by `Client.spawn()` has no users to share with.

   **Fix:** Use a [server of your own](https://virtx.sh/docs/tutorials/self-hosting/).

## Next

- [Running your own server](https://virtx.sh/docs/tutorials/self-hosting/): serve VirtX to the team you share projects with.
- [Mounting volumes](https://virtx.sh/docs/tutorials/mounting-volumes/): the volumes a project keeps.
