Skip to main content

CLI for OpenAI Structured Output

Project description

ostruct-cli

PyPI version Python Versions Documentation Status CI License: MIT

Command-line interface for working with OpenAI models and structured output, powered by the openai-structured library.

Features

  • Generate structured output from natural language using OpenAI models
  • Rich template system for defining output schemas
  • Automatic token counting and context window management
  • Streaming support for real-time output
  • Caching system for cost optimization
  • Secure handling of sensitive data

Installation

pip install ostruct-cli

Quick Start

  1. Set your OpenAI API key:
export OPENAI_API_KEY=your-api-key
  1. Create a task template file task.j2:
Extract information about the person: {{ stdin }}
  1. Create a schema file schema.json:
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "The person's full name"
    },
    "age": {
      "type": "integer",
      "description": "The person's age"
    },
    "occupation": {
      "type": "string",
      "description": "The person's job or profession"
    }
  },
  "required": ["name", "age", "occupation"]
}
  1. Run the CLI:
echo "John Smith is a 35 year old software engineer" | ostruct --task @task.j2 --schema schema.json

Output:

{
  "name": "John Smith",
  "age": 35,
  "occupation": "software engineer"
}

About Template Files

Template files use the .j2 extension to indicate they contain Jinja2 template syntax. This convention:

  • Enables proper syntax highlighting in most editors
  • Makes it clear the file contains template logic
  • Follows industry standards for Jinja2 templates

While the CLI accepts templates with any extension (when prefixed with @), we recommend using .j2 for better tooling support and clarity.

Debug Options

  • --show-model-schema: Display the generated Pydantic model schema
  • --debug-validation: Show detailed schema validation debugging
  • --verbose-schema: Enable verbose schema debugging output
  • --debug-openai-stream: Enable low-level debug output for OpenAI streaming (very verbose)
  • --progress-level {none,basic,detailed}: Set progress reporting level (default: basic)

All debug and error logs are written to:

  • ~/.ostruct/logs/ostruct.log: General application logs
  • ~/.ostruct/logs/openai_stream.log: OpenAI streaming operations logs

For more detailed documentation and examples, visit our documentation.

Development

To contribute or report issues, please visit our GitHub repository.

Development Setup

  1. Clone the repository:
git clone https://github.com/yanivgolan/ostruct.git
cd ostruct
  1. Install Poetry if you haven't already:
curl -sSL https://install.python-poetry.org | python3 -
  1. Install dependencies:
poetry install
  1. Install openai-structured in editable mode:
poetry add --editable ../openai-structured  # Adjust path as needed
  1. Run tests:
poetry run pytest

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Migration from openai-structured

If you were previously using the CLI bundled with openai-structured (pre-1.0.0), this is its new home. The migration is straightforward:

  1. Update openai-structured to version 1.0.0 or later
  2. Install ostruct-cli
  3. Replace any openai-structured CLI commands with ostruct

The functionality remains the same, just moved to a dedicated package for better maintenance and focus.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ostruct_cli-0.1.4.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ostruct_cli-0.1.4-py3-none-any.whl (61.4 kB view details)

Uploaded Python 3

File details

Details for the file ostruct_cli-0.1.4.tar.gz.

File metadata

  • Download URL: ostruct_cli-0.1.4.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for ostruct_cli-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3e93b048cb4d3313b41d6fd00abd33ad06fc1e3cb1424c964dbcb809638e5372
MD5 dc37b9e1a29322bea7b822d65c3a61a2
BLAKE2b-256 844d8746f956183614820d9ff6401f1667a57c67a7aa68b214fdd8600d4b1293

See more details on using hashes here.

Provenance

The following attestation bundles were made for ostruct_cli-0.1.4.tar.gz:

Publisher: publish.yml on yaniv-golan/ostruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ostruct_cli-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ostruct_cli-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 61.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for ostruct_cli-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ead2cefc1d7cb7975089a3389a48e33add15d8b9f440379df5886035ac2c0b47
MD5 ce7e57a62bbaf6debcc85372230cd8d5
BLAKE2b-256 1c11bdc5d9a22d70290115b85cef458db71bac459de12aa82162bd4d7909f877

See more details on using hashes here.

Provenance

The following attestation bundles were made for ostruct_cli-0.1.4-py3-none-any.whl:

Publisher: publish.yml on yaniv-golan/ostruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page