> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fiddler.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Application

> Represents a GenAI Application container for organizing GenAI application resources.

An Application is a logical container within a Project that groups related GenAI
application resources including datasets, experiments, evaluators, and monitoring
configurations. Applications provide resource organization, access control, and
lifecycle management for GenAI App monitoring workflows.

Key Features:

* **Resource Organization**: Container for related GenAI application resources
* **Project Context**: Applications are scoped within projects for isolation
* **Access Management**: Application-level permissions and access control
* **Monitoring Coordination**: Centralized monitoring and alerting configuration
* **Lifecycle Management**: Coordinated creation, updates, and deletion of resources

Application Lifecycle:

1. **Creation**: Create application with unique name within a project
2. **Configuration**: Set up datasets, evaluators, and monitoring
3. **Operations**: Publish logs, monitor performance, manage alerts
4. **Maintenance**: Update configurations and resources
5. **Cleanup**: Delete application when no longer needed

## Example

```python theme={null}
# Create a new application for fraud detection
application = Application.create(name="fraud-detection-app", project_id=project_id)
print(f"Created application: {application.name} (ID: {application.id})")
```

> [!NOTE]
>
> Applications are permanent containers - once created, the name cannot be changed.
> Deleting an application removes all contained resources and configurations.
> Consider the organizational structure carefully before creating applications.

## Attributes

**id** `UUID`

Unique identifier (UUID) of the application.

**name** `str`

Application name; unique within the project and immutable after creation.

**created\_at** `datetime`

Server-side timestamp of when the application was created.

**updated\_at** `datetime`

Server-side timestamp of when the application was last updated.

**created\_by** `UserCompact`

Compact reference (id, full name, email) to the user who created the
application.

**updated\_by** `UserCompact`

Compact reference (id, full name, email) to the user who last updated the
application.

**project** `ProjectCompact`

Compact reference (id and name) to the project containing this application.

## *classmethod* get\_by\_id()

Retrieve an application by its unique identifier.

Fetches an application from the Fiddler platform using its UUID. This is the most
direct way to retrieve an application when you know its ID.

### Parameters

**id\_** `UUID | str` *required*

The unique identifier (UUID) of the application to retrieve.
Can be provided as a UUID object or string representation.

### Returns

The application instance with all metadata and configuration.

### Raises

* **NotFound** – If no application exists with the specified ID.
* **ApiError** – If there's an error communicating with the Fiddler API.

### Example

```python theme={null}
# Get application by UUID
application = Application.get_by_id(id_="550e8400-e29b-41d4-a716-446655440000")
print(f"Retrieved application: {application.name}")
print(f"Created: {application.created_at}")
print(f"Project: {application.project.name}")
```

> [!NOTE]
>
> This method makes an API call to fetch the latest application state from the server.
> The returned application instance reflects the current state in Fiddler.

## *classmethod* get\_by\_name()

Retrieve an application by name within a project.

Finds and returns an application using its name within the specified project.
This is useful when you know the application name and project but not its UUID.
Application names are unique within a project, making this a reliable lookup method.

### Parameters

**name** `str` *required*

The name of the application to retrieve. Application names are unique
within a project and are case-sensitive.

**project\_id** `UUID | str` *required*

The UUID of the project containing the application.
Can be provided as a UUID object or string representation.

### Returns

The application instance matching the specified name.

### Raises

* **NotFound** – If no application exists with the specified name in the project.
* **ApiError** – If there's an error communicating with the Fiddler API.

### Example

```python theme={null}
# Get project instance
project = Project.get_by_name(name="fraud-detection-project")

# Get application by name within a project
application = Application.get_by_name(
    name="fraud-detection-app",
    project_id=project.id
)
print(f"Found application: {application.name} (ID: {application.id})")
print(f"Created: {application.created_at}")
print(f"Project: {application.project.name}")
```

> [!NOTE]
>
> Application names are case-sensitive and must match exactly. Use this method
> when you have a known application name from configuration or user input.

## *classmethod* list()

List all applications in a project.

Retrieves all applications that the current user has access to within the specified
project. Returns an iterator for memory efficiency when dealing with many applications.

### Parameters

**project\_id** `UUID | str` *required*

The UUID of the project to list applications from.
Can be provided as a UUID object or string representation.

### Yields

`Application` – Application instances for all accessible applications in the project.

### Raises

**ApiError** – If there's an error communicating with the Fiddler API.

### Returns

`Iterator[Application]`

### Example

```python theme={null}
# Get project instance
project = Project.get_by_name(name="fraud-detection-project")

# List all applications in a project
for application in Application.list(project_id=project.id):
    print(f"Application: {application.name}")
    print(f"  ID: {application.id}")
    print(f"  Created: {application.created_at}")

# Convert to list for counting and filtering
applications = list(Application.list(project_id=project.id))
print(f"Total applications in project: {len(applications)}")

# Find applications by name pattern
fraud_apps = [
    app for app in Application.list(project_id=project.id)
    if "fraud" in app.name.lower()
]
print(f"Fraud detection applications: {len(fraud_apps)}")
```

> [!NOTE]
>
> This method returns an iterator for memory efficiency. Convert to a list
> with list(Application.list(project\_id)) if you need to iterate multiple times or get
> the total count. The iterator fetches applications lazily from the API.

## *classmethod* create()

Create a new application in a project.

Creates a new application within the specified project on the Fiddler platform.
The application must have a unique name within the project.

### Parameters

**name** `str` *required*

Application name, must be unique within the project.

**project\_id** `UUID | str` *required*

The UUID of the project to create the application in.
Can be provided as a UUID object or string representation.

### Returns

The newly created application instance with server-assigned fields.

### Raises

* **Conflict** – If an application with the same name already exists in the project.
* **ValidationError** – If the application configuration is invalid (e.g., invalid name format).
* **ApiError** – If there's an error communicating with the Fiddler API.

### Example

```python theme={null}
# Get project instance
project = Project.get_by_name(name="fraud-detection-project")

# Create a new application for fraud detection
application = Application.create(
    name="fraud-detection-app",
    project_id=project.id
)
print(f"Created application with ID: {application.id}")
print(f"Created at: {application.created_at}")
print(f"Project: {application.project.name}")
```

> [!NOTE]
>
> After successful creation, the application instance is returned with
> server-assigned metadata. The application is immediately available
> for adding datasets, evaluators, and other resources.

## *classmethod* get\_or\_create()

Get an existing application by name or create a new one if it doesn't exist.

This is a convenience method that attempts to retrieve an application by name
within a project, and if not found, creates a new application with that name.
Useful for idempotent application setup in automation scripts and deployment pipelines.

### Parameters

**name** `str` *required*

The name of the application to retrieve or create.

**project\_id** `UUID | str` *required*

The UUID of the project to search/create the application in.
Can be provided as a UUID object or string representation.

### Returns

Either the existing application with the specified name,
or a newly created application if none existed.

### Raises

* **ValidationError** – If the application name format is invalid.
* **ApiError** – If there's an error communicating with the Fiddler API.

### Example

```python theme={null}
# Get project instance
project = Project.get_by_name(name="fraud-detection-project")

# Safe application setup - get existing or create new
application = Application.get_or_create(
    name="fraud-detection-app",
    project_id=project.id
)
print(f"Using application: {application.name} (ID: {application.id})")

# Idempotent setup in deployment scripts
application = Application.get_or_create(
    name="llm-pipeline-app",
    project_id=project.id
)

# Use in configuration management
environments = ["dev", "staging", "prod"]
applications = {}
for env in environments:
    applications[env] = Application.get_or_create(
        name=f"fraud-detection-{env}",
        project_id=project.id
    )
```

> [!NOTE]
>
> This method is idempotent - calling it multiple times with the same name
> and project\_id will return the same application. It logs when creating a new
> application for visibility in automation scenarios.

## get\_span\_fields()

Discover span attribute keys and evaluator outputs for this application.

Returns the union of attribute keys and evaluator outputs across
spans in the given time range, with coverage counts. Useful for
building field mappings before adding spans to a dataset.

### Parameters

**start\_time** `str | datetime` *required*

Start of the time range, inclusive. ISO 8601
string or a **timezone-aware** datetime. Naive datetimes
are rejected by the server; any UTC offset is accepted and
normalized to UTC server-side.

**end\_time** `str | datetime` *required*

End of the time range, exclusive. ISO 8601 string or
a **timezone-aware** datetime, same rules as
`start_time`.

**filter** `QueryCondition | None` (default: None)

Optional structured filter over span fields, using the
namespaced DSL (`Span::duration`,
`SpanAttribute::gen_ai.usage.total_tokens`,
`Evaluator::Safety::Is Toxic`). Limited to 3 levels of
nesting and 10 rules.

**search** `SearchFilter | None` (default: None)

Optional full-text search over span content.
AND-ed with `filter`.

### Returns

Span attributes and evaluator outputs with counts.

### Raises

**ApiError** – If there's an error communicating with the Fiddler API.

> [!NOTE]
>
> Discovery scans at most 10,000 matching spans. Above that it sets
> `sampled=True` and the counts describe a sample rather than the
> full set — narrow the time range or the filter when you need exact
> coverage. Attribute keys are reported exactly as stored, so they
> can be copied directly into a
> [`FieldMapping`](https://docs.fiddler.ai/sdk-api/evals/field-mapping)
> for [`Dataset.add_items_from_spans()`](https://docs.fiddler.ai/sdk-api/evals/dataset#add_items_from_spans).

### Example

```python theme={null}
from datetime import datetime, timedelta, timezone

from fiddler_evals import (
    Application,
    OperatorType,
    Project,
    QueryCondition,
    QueryRule,
)

# Get application instance
project = Project.get_by_name(name="fraud-detection-project")
application = Application.get_by_name(
    name="fraud-detection-app",
    project_id=project.id,
)

end_time = datetime.now(timezone.utc)
start_time = end_time - timedelta(days=7)

# Scope discovery to LLM spans only
llm_filter = QueryCondition(
    rules=[
        QueryRule(
            field="Span::span_type",
            operator=OperatorType.EQUAL,
            value="llm",
        ),
    ]
)

fields = application.get_span_fields(
    start_time=start_time,
    end_time=end_time,
    filter=llm_filter,
)

print(f"{fields.total_spans} spans scanned (sampled={fields.sampled})")
for attribute in sorted(fields.span_attributes, key=lambda a: -a.count):
    print(f"  {attribute.key}: {attribute.count}")
```
