Python client SDK for Middleman.ai API
Project description
Middleman.ai Python SDK
Middleman.ai の API を簡単に利用するための Python SDK です。マークダウン →PDF 変換、JSON→PPTX 変換、PDF ページ → 画像変換などの機能を提供します。
インストール
pip install middleman-ai
基本的な使い方
from middleman_ai import ToolsClient
# クライアントの初期化
client = ToolsClient(api_key="YOUR_API_KEY")
# Markdown → PDF変換
markdown_text = "# Sample\nThis is a test."
pdf_url = client.md_to_pdf(markdown_text, pdf_template_id="template-uuid")
print(f"Generated PDF URL: {pdf_url}")
CLI の使用方法
SDK はコマンドラインインターフェース(CLI)も提供しています。UV を使用して以下のように実行できます:
# APIキーの設定
export MIDDLEMAN_API_KEY=your-api-key
# Markdown → PDF変換
echo "# テスト" | uvx middleman md-to-pdf [テンプレートID]
# Markdown → DOCX変換
echo "# テスト" | uvx middleman md-to-docx
# PDF → ページ画像変換
uvx middleman pdf-to-page-images input.pdf
# DOCX → ページ画像変換
uvx middleman docx-to-page-images input.docx
# PPTX → ページ画像変換
uvx middleman pptx-to-page-images input.pptx
# XLSX → ページ画像変換
uvx middleman xlsx-to-page-images input.xlsx
# PPTXテンプレート解析
uvx middleman json-to-pptx-analyze [テンプレートID]
# PPTXテンプレート実行
echo '{"slides":[{"type":"title","placeholders":[{"name":"title","content":"テストタイトル"}]}]}' | \
uvx middleman json-to-pptx-execute [テンプレートID]
# Mermaid図表 → 画像変換
echo "graph TD; A-->B" | uvx middleman mermaid-to-image
各コマンドは標準入力からテキストを受け取るか、必要に応じてファイルパスやテンプレート ID を引数として受け取ります。
MCP Server
Middleman SDK は MCP サーバーを提供し、Claude Desktop アプリケーションなどから利用できます。
Claude Desktop 設定
Claude Desktop アプリケーションのclaude_desktop_config.jsonを以下のように設定します:
{
"mcpServers": {
"middleman": {
"command": "uvx",
"args": ["--from", "middleman-ai", "mcp-server"],
"env": {
"MIDDLEMAN_API_KEY": "xxxxx"
}
}
}
}
エラーハンドリング
from middleman_ai import ToolsClient, NotEnoughCreditError
client = ToolsClient(api_key="YOUR_API_KEY")
try:
pdf_url = client.md_to_pdf("# Test")
except NotEnoughCreditError:
print("クレジット不足です。プランをアップグレードしてください。")
except Exception as e:
print(f"エラーが発生しました: {e}")
ライセンス
MIT License
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
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 middleman_ai-0.2.0.tar.gz.
File metadata
- Download URL: middleman_ai-0.2.0.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdf65c6b15187607fa170b22624465a69ac6c6b08b228dd2e2414150898a6f3f
|
|
| MD5 |
00f22a633e0da8038f7e5bd612320132
|
|
| BLAKE2b-256 |
d423fbc3f2c220805e183e752db4a34a66477a5e9564d7b21332961cb65ecd7b
|
File details
Details for the file middleman_ai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: middleman_ai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df95bd6ae5e6f70a90de2e3a62002328bacfbcd97bb2c337afb7a98a3d3be0bc
|
|
| MD5 |
fae4ce3794c3c523127b288874e16902
|
|
| BLAKE2b-256 |
5b2244ca4be4906be3237363a9280ae7220e3c53cb600039ea96a585cf06c19a
|