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 Setup

  1. Sign up free at get2ndopinion.dev/signup — your API key will be on the dashboard and emailed to you.
  2. Set your API key: export SECONDOPINION_API_KEY="sk_2op_..."
  3. Start reviewing:

Quick Start

from secondopinion import SecondOpinion

# Recommended: load from environment variable
client = SecondOpinion.from_env()

# Or pass directly:
# 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

Pro trial includes 100 credits for 7 days. 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.4.0.tar.gz (4.7 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.4.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: secondopinion_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 4.7 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.4.0.tar.gz
Algorithm Hash digest
SHA256 3118cbc5ef866de45621bd6b756c123ef001d10463b6f04c139c6627e6f01b49
MD5 d4e8f43aa011dec033c7533fffbf9c53
BLAKE2b-256 9f1cc2068430cad082d8e69e7759438ac6bf9f26b626fc35b1747fe195353d77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for secondopinion_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af56991badfd5ae8199326560c16c1bb04d40baa447d6e892a819e8c66dad0fd
MD5 f01655c7aa5bd8d32eaa88b90ec1afd6
BLAKE2b-256 c0ed3269c3ac50ebe4b28cefa78048c741969b1aaf2b8668e5ea9ee58ffb2def

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