Skip to main content

Python SDK for the 2ndOpinion API

Project description

secondopinion-sdk

Official Python SDK for 2ndOpinion — AI-to-AI code review where Claude, Codex, and Gemini review your code together.

Installation

pip install secondopinion-sdk

Quick Start

from secondopinion import SecondOpinion

client = SecondOpinion(api_key="sk_2op_...")

# Get a code review
result = client.opinion(diff="your git diff here", llm="codex")
print(result["analysis"]["summary"])

# Ask a question
answer = client.ask(question="Is this SQL query safe?", code="SELECT * FROM users WHERE id = " + user_id)
print(answer["response"])

# Check usage
status = client.status()
print(f"Credits: {status['totalAvailable']}")

Available Methods

Method Description Credits
opinion(diff, llm, context) Single-model code review 1
ask(question, llm, code, context) Ask an AI model a question 1
review(diff, llm, context) Code review (alias for opinion) 1
explain(diff, audience) Explain changes 1
consensus(diff, context) 3-model consensus review 3
bug_hunt(diff, context) 3-model bug detection 3
security_audit(diff, context) OWASP security scan 1-3
generate_tests(diff, llm, framework) Generate tests 1
status() Check account credits 0

CI/CD Usage

Use in Python scripts for automated pipelines:

import subprocess, json
from secondopinion import SecondOpinion

client = SecondOpinion(api_key=os.environ["SECONDOPINION_API_KEY"])
diff = subprocess.check_output(["git", "diff", "HEAD~1"]).decode()

result = client.opinion(diff=diff, llm="codex")

if result["analysis"]["recommendation"] == "reject":
    print("Code review failed:", result["analysis"]["summary"])
    exit(1)

Or use the CLI with --ci for JSON output:

npx 2ndopinion analyze --ci | python -c "import sys,json; print(json.load(sys.stdin)['verdict'])"

Get an API Key

  1. Sign up at get2ndopinion.dev/signup
  2. Go to Dashboard > API Keys
  3. Create a key and pass it to the constructor

Free tier includes 5 credits/month. See all plans.

Links

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

secondopinion_sdk-0.3.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

secondopinion_sdk-0.3.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file secondopinion_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: secondopinion_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for secondopinion_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e06309fa439d7772dfde6b2873f90660ad0fb79f9a0c1e49abff03cf33e85844
MD5 522dca037242a2c8a6bf7b5d9b67d100
BLAKE2b-256 9e263fca51d278aef99891139a265e47b68d11bdf529173790188f7e8d1270f5

See more details on using hashes here.

File details

Details for the file secondopinion_sdk-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for secondopinion_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30638762b7d2bffc7e4fb17ba8c6a7a31c019f74ed5e4efa3ca9c3bb6e922f65
MD5 f928f3c9e400989349f5e3ca014417a5
BLAKE2b-256 3d546370aba71641d024960a8cca845e65cdf81819372289ba731c2acd16e9b4

See more details on using hashes here.

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