Python SDK
Official Python SDK for ArchiCore API.
Installation
pip install archicore
Requirements
- Python 3.8+
requestslibrary (installed automatically)
Quick Start
from archicore import ArchiCore
client = ArchiCore(api_key="your-api-key")
# List all projects
projects = client.projects.list()
print(projects)
Configuration
client = ArchiCore(
api_key="your-api-key", # Required
base_url="https://api.archicore.io/api/v1", # Optional
timeout=30, # Optional, in seconds
)
Environment Variables
import os
from archicore import ArchiCore
client = ArchiCore(api_key=os.environ["ARCHICORE_API_KEY"])
Projects
List Projects
projects = client.projects.list()
for project in projects:
print(f"{project['name']} - {project['status']}")
Get Project
project = client.projects.get("project-id")
print(project["name"])
print(project["stats"]["files"])
Create Project
project = client.projects.create(
name="my-project",
source="/path/to/project", # Optional
github_url="https://github.com/...", # Optional
)
Delete Project
client.projects.delete("project-id")
Index Project
status = client.projects.index("project-id", force=True)
print(status["status"])
Search
Semantic Search
results = client.projects.search(
"project-id",
query="authentication middleware",
limit=10, # Optional
threshold=0.7, # Optional
)
for result in results:
print(f"{result['file']}:{result['line']} ({result['score']:.2f})")
print(result['code'])
AI Assistant
Ask Questions
answer = client.projects.ask(
"project-id",
question="How does the authentication system work?",
context="Focus on JWT implementation", # Optional
)
print(answer["response"])
if answer.get("sources"):
print("\nSources:")
for source in answer["sources"]:
print(f" {source['file']}:{source['line']}")
Metrics
Get Project Metrics
metrics = client.projects.metrics("project-id")
print(f"Files: {metrics['totalFiles']}")
print(f"Lines: {metrics['totalLines']}")
print(f"Complexity: {metrics.get('complexity', {}).get('average', 'N/A')}")
print("\nLanguages:")
for lang, count in metrics.get("languages", {}).items():
print(f" {lang}: {count}")
Security
Get Security Report
report = client.projects.security("project-id")
summary = report["summary"]
print(f"Critical: {summary['critical']}")
print(f"High: {summary['high']}")
print(f"Medium: {summary['medium']}")
print(f"Low: {summary['low']}")
for vuln in report["vulnerabilities"]:
print(f"[{vuln['severity'].upper()}] {vuln['type']}")
print(f" {vuln['message']}")
print(f" {vuln['file']}:{vuln['line']}")
Impact Analysis
Analyze Changes
impact = client.projects.analyze(
"project-id",
files=["src/auth/login.ts", "src/auth/session.ts"],
)
print(f"Risk Level: {impact['riskLevel']}")
print(f"Affected Files: {len(impact['affectedFiles'])}")
for file in impact["affectedFiles"][:5]:
print(f" - {file}")
if impact.get("suggestions"):
print("\nSuggestions:")
for suggestion in impact["suggestions"]:
print(f" - {suggestion}")
Enterprise Analysis
For large projects with 50K+ files.
Get Estimate
estimate = client.projects.enterprise_estimate("project-id")
print(f"Total files: {estimate['totalFiles']:,}")
print(f"Project size: {estimate['totalSizeMB']:.1f} MB")
print(f"Recommended tier: {estimate['recommendation'].upper()}")
print("\nLanguage Distribution:")
for lang, count in sorted(
estimate["languageDistribution"].items(),
key=lambda x: x[1],
reverse=True
)[:5]:
print(f" {lang}: {count:,}")
Start Enterprise Indexing
# Quick analysis with smart sampling
task = client.projects.enterprise_index(
"project-id",
tier="quick",
sampling_strategy="smart"
)
print(f"Task ID: {task['taskId']}")
# Standard with focus directories
task = client.projects.enterprise_index(
"project-id",
tier="standard",
sampling_strategy="hot-files",
focus_directories=["src/core", "src/api"],
exclude_patterns=["test", "spec", "__pycache__"]
)
# Incremental indexing
task = client.projects.enterprise_index(
"project-id",
tier="standard",
incremental_since="2024-01-01" # or git commit hash
)
Preview Files
preview = client.projects.enterprise_files_preview(
"project-id",
tier="standard",
strategy="smart"
)
print(f"Would analyze {preview['totalSelected']:,} of {preview['maxAllowed']:,} files")
print("\nSample files:")
for file in preview["files"][:10]:
print(f" {file}")
Check Incremental Changes
# Since date
changes = client.projects.enterprise_incremental(
"project-id",
since="2024-01-01"
)
# Since commit hash
changes = client.projects.enterprise_incremental(
"project-id",
since="abc123f"
)
print(f"Changed files: {changes['changedFiles']}")
for file in changes["files"][:10]:
print(f" {file}")