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.1.tar.gz (3.5 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.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for secondopinion_sdk-0.3.1.tar.gz
Algorithm Hash digest
SHA256 a21c53e2d9049cfc45cd30caebea1a5243d52291ae44e6ec2a27986f186093a6
MD5 1f902387560beb11039dc5bafaf2bfbb
BLAKE2b-256 9dfb30409f3bbe2e76e898d12764fd280ac6067ff34bf6274854078df815f35b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for secondopinion_sdk-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2590d9be2a19a6b050a48f431ddf37af70e0d3bd41b3b3218ef19c592d1e2959
MD5 7ff4aefd8ecd79a72fdf25b20fc55828
BLAKE2b-256 b1c1a19f2482332d853c7310e93b93a9846ea1008bb69bdf6c60adb25f4df35a

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