Service definition examples

Here are the service definition files for a few builtin applications:

Dashboard Services

services:
  - name: "dashboard.router"
    description: "Router for the dashboard controllers, shared between different subcontrollers."
    type: http_router.Router
    arguments:
      trim_last_slash: true

  - name: "dashboard.controller"
    description: "Main controller for the dashboard."
    type: harp_apps.dashboard.controllers.DashboardController
    arguments:
      router: !ref dashboard.router

  - name: "dashboard.controller.blobs"
    description: "Sub-controller for the blobs-related routes of the dashboard."
    type: harp_apps.dashboard.controllers.blobs.BlobsController
    arguments:
      router: !ref dashboard.router
      storage: !ref storage.blobs

  - name: "dashboard.controller.overview"
    description: "Sub-controller for the overview-related routes of the dashboard."
    type: harp_apps.dashboard.controllers.overview.OverviewController
    arguments:
      router: !ref dashboard.router
      storage: !ref storage

  - name: "dashboard.controller.system"
    description: "Sub-controller for the system-related routes of the dashboard."
    type: harp_apps.dashboard.controllers.system.SystemController
    arguments:
      router: !ref dashboard.router
      storage: !ref storage

  - name: "dashboard.controller.transactions"
    description: "Sub-controller for the transactions-related routes of the dashboard."
    type: harp_apps.dashboard.controllers.transactions.TransactionsController
    arguments:
      router: !ref dashboard.router
      storage: !ref storage

Read the service reference for dashboard, generated from this file.

HTTP Client Services

services:
  # Main http client service, using httpx
  - name: "http_client"
    type: [!cfg "type", "httpx.AsyncClient"]
    defaults:
      transport: !ref "http_client.proxy_transport"
    arguments: [!cfg "arguments", {}]

  # Proxy filter, decorating the regular http transport
  - name: "http_client.proxy_transport"
    type: [!cfg "proxy_transport.type", "harp_apps.http_client.transport.AsyncFilterableTransport"]
    defaults:
      - transport: !ref "http_client.transport"
    arguments: [!cfg "proxy_transport.arguments", {}]

  # Default httpx transport implementation, handling the actual http requests
  - name: "http_client.transport"
    type: [!cfg "transport.type", "httpx.AsyncHTTPTransport"]
    arguments: [!cfg "transport.arguments", {}]

  # Cache implementation, using hishel, if enabled in config (default)
  - condition: [!cfg "cache.enabled", !!bool "true"]
    services:
      # Override http_client with cache transport
      - name: "http_client"
        override: "merge"
        defaults:
          transport: !ref "http_client.cache.transport"

      # Caching transport decorator, wrapping the proxy transport
      - name: "http_client.cache.transport"
        type: [!cfg "cache.transport.type", "hishel.AsyncCacheTransport"]
        defaults:
          transport: !ref "http_client.proxy_transport"
          storage: !ref "http_client.cache.storage"
          controller: !ref "http_client.cache.controller"
        arguments: [!cfg "cache.transport.arguments", {}]

      # Caching controller, responsible for determining what is cacheable
      - name: "http_client.cache.controller"
        type: [!cfg "cache.controller.type", "hishel.Controller"]
        arguments: [!cfg "cache.controller.arguments", {}]

      # Cache storage implementation, a.k.a how to store and retrieve cache data
      - name: "http_client.cache.storage"
        base: [!cfg "cache.storage.base", "hishel.AsyncBaseStorage"]
        type: [!cfg "cache.storage.type", "harp_apps.http_client.contrib.hishel.storages.AsyncStorage"]
        defaults:
          storage: !ref ["storage.blobs", "http_client.fallback_blob_storage"]
        arguments: [!cfg "cache.storage.arguments", {}]

      # Fallback blob storage, used by the cache storage if no other storage is available
      - name: "http_client.fallback_blob_storage"
        type: harp_apps.storage.services.blob_storages.memory.MemoryBlobStorage

Read the service reference for http_client, generated from this file.

Storage Services

services:
  - name: "storage"
    description: "Main storage facade, most probably based on the underlying sql/sqlalchemy implementation."
    base: harp_apps.storage.types.storage.IStorage
    type: harp_apps.storage.services.sql.SqlStorage

  - name: "storage.blobs"
    description: Placeholder for Blob Storage. Will be overriden by specific implementations.
    base: harp_apps.storage.types.IBlobStorage
    arguments: [!cfg "blobs.arguments", {}]

  - name: "storage.engine"
    description: "SQLAlchemy Engine."
    base: sqlalchemy.ext.asyncio.AsyncEngine
    type: harp_apps.storage.engines.SQLAlchemyEngine
    constructor: from_url
    arguments: { "url": [!cfg "url"] }

  - name: "storage.worker"
    description: "Storage async worker"
    base: harp_apps.storage.worker.StorageAsyncWorkerQueue

  - condition: [!cfg "blobs.type == 'sql'", !!bool "true"]
    services:
      - name: "storage.blobs"
        description: "SQL based Blob Storage."
        override: "merge"
        type: harp_apps.storage.services.blob_storages.sql.SqlBlobStorage
        defaults: {} #db: !ref "storage.sql"

  - condition: !cfg "blobs.type == 'redis'"
    services:
      - name: "storage.blobs"
        description: "Redis based Blob Storage."
        override: "merge"
        type: harp_apps.storage.services.blob_storages.redis.RedisBlobStorage
        defaults:
          client: !ref "storage.redis"

  - condition: [!cfg "redis is not None", !cfg "blobs.type == 'redis'"]
    services:
      - name: "storage.redis"
        description: "Asynchronous Redis Client."
        base: [!cfg "redis.base", "redis.asyncio.Redis"]
        type: [!cfg "redis.type", "harp_apps.storage.services.redis.Redis"]
        constructor: [!cfg "redis.constructor", "from_url"]
        defaults:
          url: !cfg ["redis.url", "redis://localhost:6379/0"]
        arguments: [!cfg "redis.arguments", {}]

Read the service reference for storage, generated from this file.