# Projects

Projects are the main organizational tool in DBNL. Each Project lives within a [Namespace](https://docs.dbnl.com/v0.24.x/access-controls/organization-and-namespaces#namespaces) in your [Organization](https://docs.dbnl.com/v0.24.x/access-controls/organization-and-namespaces#organization) and is accessible by everyone in that Namespace. Generally, you'll create one Project for every AI application that you'd like to test with DBNL. The list of Projects available to you is the default landing page when browsing to the DBNL UI.

## What's in a Project?

Your Project will contain all of your app's [Runs](https://docs.dbnl.com/v0.24.x/using-distributional/runs) — a collection of results from your app — and all of the [tests](https://docs.dbnl.com/v0.24.x/using-distributional/tests) that you've defined to monitor the behavior of your app. It also has a name and various configurable properties like a [default Baseline Run](https://docs.dbnl.com/v0.24.x/runs/setting-a-baseline-run#setting-a-default-baseline-run) and [Notifications](https://docs.dbnl.com/v0.24.x/using-distributional/notifications).

<figure><img src="https://content.gitbook.com/content/xVrDMviYOLuFCuRxVlSy/blobs/A6TSrhTIZJLhKyucj49b/image.png" alt=""><figcaption><p>The Project Header in DBNL</p></figcaption></figure>

## Creating a Project

### From Scratch

You can create a Project either via the UI or the SDK:

{% tabs %}
{% tab title="UI" %}
Simply click the "Create Project" button from the Project list view and choose an option.

<figure><img src="https://content.gitbook.com/content/xVrDMviYOLuFCuRxVlSy/blobs/UdXHvkVoGRPUK3feko9Y/image.png" alt=""><figcaption><p>Project List</p></figcaption></figure>
{% endtab %}

{% tab title="SDK" %}
Creating a project with the SDK can be done easily with the [`create_project`](#creating-a-project) function.

```python
import dbnl
dbnl.login()

project = dbnl.create_project(
    name="My Project",
    description="This is a very important project."
)
```

{% endtab %}
{% endtabs %}

### Copying a Project

You can quickly copy an existing Project to get up and running with a new one. This will copy the following items into your new Project:

* Test specifications
* Test tags
* Notification rules

There are a couple of ways to copy a Project.

#### Exporting and Importing

Any Project can be exported to a JSON file; that JSON file can then be adjusted to your liking and imported as a new Project. This is doable both via the UI and the SDK:

{% tabs %}
{% tab title="UI" %}

#### Exporting

To export a Project, simply click the download icon on the Project page, in the header.

<figure><img src="https://content.gitbook.com/content/xVrDMviYOLuFCuRxVlSy/blobs/JJzGK4OEenxgpZHxWen8/image.png" alt=""><figcaption><p>Exporting a Project</p></figcaption></figure>

This will download the Project's JSON to your computer. There is an example JSON in the expandable section below.

#### Importing

Once you have a Project JSON, you can edit it as you'd like, and then import it by clicking the "Create Project" button on the Project list and then clicking the "Copy an Existing Project from File" option.

<figure><img src="https://content.gitbook.com/content/xVrDMviYOLuFCuRxVlSy/blobs/21f77QGljabvHL6K7abd/image.png" alt=""><figcaption><p>Importing a Project</p></figcaption></figure>

Fill out the name and description, click "Create Project", and you're all set!
{% endtab %}

{% tab title="SDK" %}
Exporting and importing a Project is done easily via the SDK functions `export_project_as_json` and `import_project_from_json`.&#x20;

```python
import dbnl
dbnl.login()

# Export
project_1 = dbnl.get_or_create_project(name="Existing Project")
export_json = dbnl.export_project_as_json(project=proj1)
# Adjust the project values as you'd like. You will need to change the name.
# An example of the JSON structure is in the collapsible section below
export_json["project"]["name"] = "New Project"

# Import
project_2 = dbnl.import_project_from_json(params=export_json)
```

{% endtab %}
{% endtabs %}

<details>

<summary>Sample Project JSON</summary>

```json
{
    "project": {
        "name": "My Project",
        "description": "This is my project."
    },
    "notification_rules": [
        {
            "conditions": [
                {
                    "assertion_name": "less_than",
                    "assertion_params": { "other": 0.85 },
                    "query_name": "test_status_percentage_query",
                    "query_params": {
                        "exclude_tag_ids": [],
                        "include_tag_ids": [],
                        "require_tag_ids": [],
                        "statuses": ["PASSED"]
                    }
                }
            ],
            "name": "Alert if passed tests are less than 85%",
            "notification_integration_names": ["Notification channel"],
            "status": "ENABLED",
            "trigger": "test_session.failed"
        }
    ],
    "tags": [
        {
            "name": "my-tag",
            "description" :"This is my tag."
        }
    ],
    "test_specs": [
        {
            "assertion": { "name": "less_than", "params": { "other": 0.5 } },
            "description": "Testing the difference in the example statistic",
            "name": "Gr.0: Non Parametric Difference: Example_Statistic",
            "statistic_inputs": [
                {
                    "select_query_template": {
                        "filter": null,
                        "select": "{EXPERIMENT}.Example_Statistic"
                    }
                },
                {
                    "select_query_template": {
                        "filter": null,
                        "select": "{BASELINE}.Example_Statistic"
                    }
                }
            ],
            "statistic_name": "my_stat",
            "statistic_params": {},
            "tag_names": ["my-tag"]
        }
    ]
}
```

</details>

#### Copying

You can also just directly copy a given Project. Again, this can be done via the UI or the SDK:

{% tabs %}
{% tab title="UI" %}
There are two ways to copy a Project from the UI:

#### From the "Create Project" Modal

In the Project list, after you click "Create Project", you can click to the "Copy an Existing Project" option and choose a Project from the dropdown.

<figure><img src="https://content.gitbook.com/content/xVrDMviYOLuFCuRxVlSy/blobs/173xtZnuIekuknByh60M/image.png" alt=""><figcaption><p>Copying a Project</p></figcaption></figure>

#### From a Project Page

While viewing a Project, you can click the copy icon in the header to copy it to a new Project.

<figure><img src="https://content.gitbook.com/content/xVrDMviYOLuFCuRxVlSy/blobs/AOB9VA4icryEu2LbcB8U/image.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="SDK" %}
Copying a Project is done easily via the SDK function `copy_project`.

```python
import dbnl
dbnl.login()


project_1 = dbnl.get_or_create_project(name="Existing Project")
project_2 = dbnl.copy_project(project=project_1, name="New Project")
```

{% endtab %}
{% endtabs %}
