Metadata-Version: 2.4
Name: runtimeconditions-common-integrations
Version: 0.3.0
Summary: The everyday services most workloads depend on: web APIs, email, databases and caches. A Condition says what the workload needs, so the platform knows what to provide.
Project-URL: Repository, https://github.com/runtimeconditions/extensions
Requires-Python: >=3.12
Description-Content-Type: text/markdown

<!-- Code generated by runtimeconditions-binding-emitter 0.1.0 from model 088a912636849829e6faafd2f5d9f2f9e41f76c385689c69b3e9082fff0bd4ad; DO NOT EDIT. -->

# runtimeconditions-common-integrations

The everyday services most workloads depend on: web APIs, email, databases and caches. A Condition says
what the workload needs, so the platform knows what to provide.

Choose the kind by what the workload does. Use api when it calls another service, with interface type
http for a web API or smtp for sending email. Use datastore when it keeps data in a database, with
relational for SQL databases such as PostgreSQL or MySQL, or document for databases such as MongoDB.
Use cache when it keeps fast, temporary data in a key/value store such as Redis or Memcached.

Most details are optional. Leave a field out when any choice works for the workload, and the platform
decides. Set it when the workload needs something specific: engine: postgres means only PostgreSQL will
do. Two interfaces need a little more: http needs the API document, the list of calls, or both, and smtp
needs the operations the workload performs, such as send.

To say how the workload finds what it depends on, for example which environment variable holds the
database URL, add the env-configuration extension. When a more specific extension exists for a service,
such as aws.s3 for Amazon S3 or nats.service for NATS, use that one instead.

```sh
pip install runtimeconditions-common-integrations
```

Runtime Conditions extension: https://runtimeconditions.io/extensions/rc/common-integrations/v1alpha4/runtimeconditions.extension.yaml

## Conditions

Every Condition part this package defines, with the fields you can set. Select a line to open it.

<details>
<summary><b>api</b> · <code>http</code>: The API is reached over HTTP.</summary>

`Http` is the `interface` of an `api` Condition.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `operations` | `HttpOperations \| None` | no | The HTTP operations the workload calls. A platform can use them to allow only these calls. List at least one operation. |
| `operations[].method` | `Method` | yes | HTTP method of the operation. Must be one of the defined methods.<br>Values:<br>`DELETE`: Delete a resource.<br>`GET`: Read a resource.<br>`HEAD`: Read only the headers of a resource.<br>`OPTIONS`: Ask which methods a resource supports.<br>`PATCH`: Change part of a resource.<br>`POST`: Create a resource or submit data.<br>`PUT`: Replace a resource.<br>`TRACE`: Echo the request back, for diagnostics. |
| `operations[].path` | `str` | yes | Request path of the operation, for example /todos/{id}, with path parameters in braces. Must not be empty. |
| `operations[].request_body_schema` | `RequestBodySchema \| None` | no | Shape of the request body that the workload sends. |
| `operations[].response_schema` | `ResponseSchema \| None` | no | Shape of the response body that the workload expects back. |
| `spec` | `Spec \| None` | no | A machine-readable description of the API that the workload depends on. Requires format and uri. No other properties are allowed. |
| `spec.format` | `Format` | yes | Format of the API document. Must be openapi.<br>Values:<br>`openapi`: An OpenAPI document. |
| `spec.uri` | `str` | yes | Where the API document can be found, for example catalog://api/default/todos-api. Must not be empty. |
| `spec.version` | `str \| None` | no | The API version the workload is written against. Must be an exact version (1.2.0 or =1.2.0), a comparison (>1.2.0, >=1.2.0, <2.0.0, <=2.0.0), a caret range (^1.2.0) or a tilde range (~1.2.0). |

</details>

<details>
<summary><b>api</b> · <code>smtp</code>: An SMTP mail server that the workload uses to send email, such as sign-up confirmations, password resets or alerts.</summary>

`Smtp` is the `interface` of an `api` Condition.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `operations` | `SmtpOperations` | yes | The SMTP operations the workload performs. List at least one operation, without repeats.<br>Values:<br>`send`: Submit an email for delivery. |

</details>

<details>
<summary><b>cache</b> · <code>key_value</code>: A key/value store, such as Redis or Memcached, for data the workload reads often and can afford to lose.</summary>

`KeyValue` is the `interface` of a `cache` Condition.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `engine` | `KeyValueEngine \| None` | no | The cache engine the workload needs. Optional. When present, must be one of the defined engine values. Leave it out if any engine of this type works.<br>Values:<br>`memcached`: Memcached, a simple in-memory cache.<br>`redis`: Redis, an in-memory key/value store. |

</details>

<details>
<summary><b>datastore</b> · <code>document</code>: A document database that stores JSON-like records, such as MongoDB.</summary>

`Document` is the `interface` of a `datastore` Condition.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `engine` | `DocumentEngine \| None` | no | The document database engine the workload needs. Optional. When present, must be one of the defined engine values. Leave it out if any engine of this type works.<br>Values:<br>`couchbase`: Couchbase.<br>`mongodb`: MongoDB. |

</details>

<details>
<summary><b>datastore</b> · <code>relational</code>: A relational (SQL) database, such as PostgreSQL or MySQL, where data lives in tables.</summary>

`Relational` is the `interface` of a `datastore` Condition.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `engine` | `RelationalEngine \| None` | no | The relational database engine the workload needs. Optional. When present, must be one of the defined engine values. Leave it out if any engine of this type works.<br>Values:<br>`mariadb`: MariaDB.<br>`mysql`: MySQL.<br>`oracle`: Oracle Database.<br>`postgres`: PostgreSQL.<br>`sqlite`: SQLite, an embedded file-based database.<br>`sqlserver`: Microsoft SQL Server. |

</details>

## api

`api` declares a `api` Condition.

The workload calls another service through a network API, such as an HTTP API or an SMTP mail server.

Example: a workload that reads todos from an HTTP API described by an OpenAPI document.

```python
from runtimeconditions_common_integrations import (
    Format,
    Http,
    HttpOperationsItem,
    Method,
    Spec,
    api,
)

api(
    Http(
        operations=[HttpOperationsItem(method=Method.GET, path="/todos/{id}")],
        spec=Spec(
            format=Format.OPENAPI,
            uri="catalog://api/default/todos-api",
            version="1.0.0",
        ),
    ),
)
```

In a Profile, this declares:

```yaml
kind: api
interface:
  type: http
  spec:
    format: openapi
    uri: catalog://api/default/todos-api
    version: 1.0.0
  operations:
    - method: GET
      path: /todos/{id}
```

Example: a workload that sends email through an SMTP server.

```python
from runtimeconditions_common_integrations import Smtp, SmtpOperationsItem, api

api(Smtp(operations=[SmtpOperationsItem.SEND]))
```

In a Profile, this declares:

```yaml
kind: api
interface:
  type: smtp
  operations: [send]
```

## cache

`cache` declares a `cache` Condition.

The workload keeps frequently used data in a cache for fast access.

Example: a workload that needs Redis.

```python
from runtimeconditions_common_integrations import KeyValue, KeyValueEngine, cache

cache(KeyValue(engine=KeyValueEngine.REDIS))
```

In a Profile, this declares:

```yaml
kind: cache
interface:
  type: key_value
  engine: redis
```

Example: a workload that accepts any key/value cache.

```python
from runtimeconditions_common_integrations import KeyValue, cache

cache(KeyValue())
```

In a Profile, this declares:

```yaml
kind: cache
interface:
  type: key_value
```

## datastore

`datastore` declares a `datastore` Condition.

The workload stores and reads persistent data in a database.

Example: a workload that needs a PostgreSQL database.

```python
from runtimeconditions_common_integrations import (
    Relational,
    RelationalEngine,
    datastore,
)

datastore(Relational(engine=RelationalEngine.POSTGRES))
```

In a Profile, this declares:

```yaml
kind: datastore
interface:
  type: relational
  engine: postgres
```

Every class, field and enum member is documented in the package's docstrings.
