CLI for OpenAI Structured Output
Project description
ostruct-cli
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
- Set your OpenAI API key:
export OPENAI_API_KEY=your-api-key
- Create a task template file
task.j2:
Extract information about the person: {{ stdin }}
- 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"]
}
- 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
- Clone the repository:
git clone https://github.com/yanivgolan/ostruct.git
cd ostruct
- Install Poetry if you haven't already:
curl -sSL https://install.python-poetry.org | python3 -
- Install dependencies:
poetry install
- Install openai-structured in editable mode:
poetry add --editable ../openai-structured # Adjust path as needed
- 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:
- Update openai-structured to version 1.0.0 or later
- Install ostruct-cli
- Replace any
openai-structuredCLI commands withostruct
The functionality remains the same, just moved to a dedicated package for better maintenance and focus.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ostruct_cli-0.3.0.tar.gz.
File metadata
- Download URL: ostruct_cli-0.3.0.tar.gz
- Upload date:
- Size: 61.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49fb25a00de80df219d03b1e80070fafdcf5666876cbaf84362d98ce295708de
|
|
| MD5 |
6cb077ddbe2e148bfc0bb869427d2274
|
|
| BLAKE2b-256 |
de8810d4dc840971e40c5f3fe9b89ed9695e8d31f16fea039873b8fb48a1c493
|
Provenance
The following attestation bundles were made for ostruct_cli-0.3.0.tar.gz:
Publisher:
publish.yml on yaniv-golan/ostruct
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ostruct_cli-0.3.0.tar.gz -
Subject digest:
49fb25a00de80df219d03b1e80070fafdcf5666876cbaf84362d98ce295708de - Sigstore transparency entry: 168271367
- Sigstore integration time:
-
Permalink:
yaniv-golan/ostruct@95cb3565ccf1c052dcc304dfda99c0e96d21c6f1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/yaniv-golan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95cb3565ccf1c052dcc304dfda99c0e96d21c6f1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ostruct_cli-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ostruct_cli-0.3.0-py3-none-any.whl
- Upload date:
- Size: 70.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c120dcc767a10c7a0b4c46b10358dfa230687b65354138b140d2e45f7a24d96f
|
|
| MD5 |
1fa7f8527f6ddb059cf747f485fc5ce1
|
|
| BLAKE2b-256 |
8021184df2154060af6028e6cd6ee6316807f6328cd50cb0ad736c54f29a385c
|
Provenance
The following attestation bundles were made for ostruct_cli-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on yaniv-golan/ostruct
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ostruct_cli-0.3.0-py3-none-any.whl -
Subject digest:
c120dcc767a10c7a0b4c46b10358dfa230687b65354138b140d2e45f7a24d96f - Sigstore transparency entry: 168271369
- Sigstore integration time:
-
Permalink:
yaniv-golan/ostruct@95cb3565ccf1c052dcc304dfda99c0e96d21c6f1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/yaniv-golan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95cb3565ccf1c052dcc304dfda99c0e96d21c6f1 -
Trigger Event:
release
-
Statement type: