Skip to main content

Official Python SDK for view0x - Smart Contract Security Analysis Platform

Project description

view0x Python SDK

Official Python SDK for view0x - Smart Contract Security Analysis Platform.

Installation

pip install view0x

Quick Start

from view0x_sdk import View0xSDK, View0xConfig

# Initialize the SDK with your API key
config = View0xConfig(
    api_key="your-api-key-here",
    # base_url="https://api.view0x.com",  # Optional: custom API URL
    # timeout=30  # Optional: request timeout in seconds
)
client = View0xSDK(config)

# Create an analysis
analysis = client.create_analysis(
    contract_code="""
    pragma solidity ^0.8.0;
    contract MyContract {
      // Your contract code
    }
    """,
    contract_name="MyContract"
)

print(f"Analysis ID: {analysis['id']}")
print(f"Status: {analysis['status']}")

# Get analysis results
result = client.get_analysis(analysis['id'])
print(f"Vulnerabilities found: {len(result.get('vulnerabilities', []))}")

Features

  • Full Python 3.8+ support with type hints
  • Comprehensive API coverage
  • Automatic authentication handling
  • Robust error handling
  • Repository analysis (GitHub/GitLab)
  • Webhook management
  • Analytics and reporting
  • Zero hardcoded values - fully configurable

API Reference

Authentication

# Login
result = client.login(
    email="user@example.com",
    password="password"
)
token = result['token']
user = result['user']

# Register
result = client.register(
    name="John Doe",
    email="john@example.com",
    password="securepassword",
    company="My Company"  # optional
)

# Get current user
user = client.get_current_user()

Analysis

# Create analysis
analysis = client.create_analysis(
    contract_code=solidity_code,
    contract_name="MyContract",  # optional
    options={}  # optional
)

# Get analysis by ID
analysis = client.get_analysis("analysis-id")

# Get analysis history with pagination
history = client.get_analysis_history(
    page=1,
    limit=10,
   search="MyContract",  # optional
    sort_by="createdAt",  # optional
    sort_order="DESC"  # optional
)

# Generate report
pdf_bytes = client.generate_report("analysis-id", format="pdf")
# Save to file
with open("report.pdf", "wb") as f:
    f.write(pdf_bytes)

# Share analysis
share_info = client.share_analysis("analysis-id")
print(f"Share URL: {share_info['shareUrl']}")

# Revoke share
client.revoke_share("analysis-id")

Repository Analysis

# Analyze GitHub repository
analyses = client.analyze_github_repository(
    repository_url="https://github.com/user/repo",
    branch="main",  # optional
    token="github-token"  # optional, for private repos
)

# Analyze GitLab repository
analyses = client.analyze_gitlab_repository(
    repository_url="https://gitlab.com/user/repo",
    branch="main",  # optional
    token="gitlab-token"  # optional, for private repos
)

# Auto-detect platform
analyses = client.analyze_repository(
    repository_url="https://github.com/user/repo"
)

Webhooks

# Create webhook
webhook = client.create_webhook(
    url="https://myapp.com/webhook",
    events=["analysis.completed", "analysis.failed"],
    secret="webhook-secret"  # optional
)

# Get all webhooks
webhooks = client.get_webhooks()

# Update webhook
updated = client.update_webhook(
    webhook_id="webhook-id",
    url="https://myapp.com/new-webhook",
    events=["analysis.completed"],
    secret="new-secret",
    is_active=True
)

# Delete webhook
client.delete_webhook("webhook-id")

# Test webhook
client.test_webhook("webhook-id")

Analytics

# Get analytics dashboard
dashboard = client.get_analytics_dashboard(
    date_range="7d",  # optional: 7d, 30d, 90d
    start_date="2024-01-01",  # optional
    end_date="2024-01-31"  # optional
)

# Get endpoint-specific analytics
stats = client.get_endpoint_analytics("/api/analysis")

# Export analytics
csv_bytes = client.export_analytics(format="csv")
json_bytes = client.export_analytics(format="json")

Error Handling

try:
    analysis = client.create_analysis(contract_code=code)
except Exception as e:
    print(f"Analysis failed: {str(e)}")

Environment Configuration

The SDK respects environment variables:

# Use custom API URL
export VIEW0X_API_URL=https://api.view0x.com

# Set default timeout
export VIEW0X_TIMEOUT=30

Type Hints

The SDK includes type hints for better IDE support:

from view0x_sdk import View0xSDK, View0xConfig
from typing import List, Dict, Any

config: View0xConfig = View0xConfig(api_key="key")
client: View0xSDK = View0xSDK(config)

analysis: Dict[str, Any] = client.get_analysis("id")
vulnerabilities: List[Dict[str, Any]] = analysis.get("vulnerabilities", [])

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black view0x_sdk

# Type checking
mypy view0x_sdk

# Linting
flake8 view0x_sdk

Contributing

See CONTRIBUTING.md

License

MIT © Nsisong Labs

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

view0x-1.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

view0x-1.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file view0x-1.0.1.tar.gz.

File metadata

  • Download URL: view0x-1.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for view0x-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6a6da887af3531246c2c125dac391072fdc758f45a3a5b7f6b732a988bd6538d
MD5 181058d291d911cf99e717fa5e528ac4
BLAKE2b-256 f62b174dcfe9a85b5c40516efadc2b93f3ecf37db10481f4c6c0088b99f9a028

See more details on using hashes here.

File details

Details for the file view0x-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: view0x-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for view0x-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1e20013e1ea20c4d670073d637fcfc3f2170747e02ce78b90b900672806b3b4
MD5 4a25c164d422e37a656f13503c65a9c3
BLAKE2b-256 0aed2d346cbd6f8485714e7dea50c7df7db8ce2a225f52f751e736af85c04e93

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