LogoLogo
WebsiteSlack
0.32
0.32
  • Get started
  • Clusters
    • Management
      • Auth
      • Create
      • Update
      • Delete
      • Environments
    • Instances
      • Multi-instance
      • Spot instances
    • Observability
      • Logging
      • Metrics
    • Networking
      • Load balancers
      • VPC peering
      • HTTPS
      • Custom domain
    • Advanced
      • Setting up kubectl
      • Private Docker registry
  • Workloads
    • Realtime APIs
      • Example
      • Predictor
      • Configuration
      • Models
      • Parallelism
      • Server-side batching
      • Autoscaling
      • Statuses
      • Metrics
      • Multi-model
        • Example
        • Configuration
        • Caching
      • Traffic Splitter
        • Example
        • Configuration
      • Troubleshooting
    • Async APIs
      • Example
      • Predictor
      • Configuration
      • Statuses
      • Webhooks
      • Metrics
    • Batch APIs
      • Example
      • Predictor
      • Configuration
      • Jobs
      • Statuses
      • Metrics
    • Task APIs
      • Example
      • Definition
      • Configuration
      • Jobs
      • Statuses
      • Metrics
    • Dependencies
      • Example
      • Python packages
      • System packages
      • Custom images
  • Clients
    • Install
    • Uninstall
    • CLI commands
    • Python client
Powered by GitBook
On this page
  • Deploy using the Python Client
  • Deploy using the CLI
  1. Workloads
  2. Dependencies

Example

You can deploy an API by providing a project directory. Cortex will save the project directory and make it available during API initialization.

project/
  ├── model.py
  ├── util.py
  ├── predictor.py
  ├── requirements.txt
  └── ...

You can define your Predictor class in a separate python file and import code from your project.

# predictor.py

from model import MyModel

class PythonPredictor:
    def __init__(self, config):
        model = MyModel()

    def predict(payload):
        return model(payload)

Deploy using the Python Client

import cortex

api_spec = {
    "name": "text-generator",
    "kind": "RealtimeAPI",
    "predictor": {
        "type": "python",
        "path": "predictor.py"
    }
}

cx = cortex.client("aws")
cx.create_api(api_spec, project_dir=".")

Deploy using the CLI

# api.yaml

- name: text-generator
  kind: RealtimeAPI
  predictor:
    type: python
    path: predictor.py
cortex deploy api.yaml
PreviousDependenciesNextPython packages

Last updated 4 years ago