Skip to main content

Nexarch SDK for runtime architecture intelligence and observability

Project description

Nexarch SDK - Python

Runtime architecture intelligence SDK for FastAPI applications.

Installation

From PyPI (once published)

pip install nexarch-sdk

From Source (Development)

cd SDK
pip install -e .

Quick Start

Basic Usage

from fastapi import FastAPI
from nexarch import NexarchSDK

# Create your FastAPI app
app = FastAPI(title="My API")

# Initialize Nexarch SDK
sdk = NexarchSDK(
    api_key="your_api_key_here",
    environment="production",
    log_file="nexarch_telemetry.json"
)

# Attach SDK to your app (auto-injects middleware and router)
sdk.init(app)

# Your existing routes
@app.get("/")
def read_root():
    return {"message": "Hello World"}

@app.get("/users/{user_id}")
def get_user(user_id: int):
    return {"user_id": user_id, "name": "John Doe"}

One-Line Initialization

from fastapi import FastAPI
from nexarch import NexarchSDK

app = FastAPI()

# Initialize in one line
NexarchSDK.start(app, api_key="your_api_key")

What Gets Captured

The SDK automatically captures:

  • All HTTP Requests: Method, path, query parameters, latency, status codes
  • All Errors: Exception types, messages, full tracebacks
  • Performance Metrics: Request latency, throughput, error rates
  • Dependency Calls: Database queries, external API calls (future)

Auto-Injected Endpoints

The SDK automatically adds internal management endpoints:

# Check SDK health
GET /__nexarch/health

# Get all telemetry data
GET /__nexarch/telemetry

# Get telemetry statistics
GET /__nexarch/telemetry/stats

# Get only errors
GET /__nexarch/telemetry/errors

# Get only request spans
GET /__nexarch/telemetry/spans

# Clear all telemetry
DELETE /__nexarch/telemetry

Local Telemetry Storage

All telemetry is stored locally in JSON format:

[
  {
    "type": "span",
    "timestamp": "2026-04-02T13:00:00.000Z",
    "data": {
      "trace_id": "abc-123",
      "operation": "GET /users/1",
      "latency_ms": 45.2,
      "status_code": 200,
      "status": "ok"
    }
  },
  {
    "type": "error",
    "timestamp": "2026-04-16T10:31:00.000Z",
    "data": {
      "error_type": "ValueError",
      "error_message": "Invalid user ID",
      "traceback": "..."
    }
  }
]

Configuration Options

sdk = NexarchSDK(
    api_key="your_api_key",              # Required: Your Nexarch API key
    environment="production",             # Optional: Environment name
    log_file="nexarch_telemetry.json",   # Optional: Local log file path
    observation_duration="3h",            # Optional: How long to observe
    sampling_rate=1.0,                    # Optional: Sample rate (0.0-1.0)
    enable_local_logs=True                # Optional: Enable local logging
)

Example: Complete FastAPI App

from fastapi import FastAPI, HTTPException
from nexarch import NexarchSDK

app = FastAPI(title="User Service")

# Initialize Nexarch
sdk = NexarchSDK(
    api_key="demo_api_key",
    environment="production",
    log_file="telemetry.json"
)
sdk.init(app)

# Simulated database
users_db = {
    1: {"id": 1, "name": "Alice"},
    2: {"id": 2, "name": "Bob"}
}

@app.get("/")
def root():
    return {"message": "User Service API"}

@app.get("/users/{user_id}")
def get_user(user_id: int):
    if user_id not in users_db:
        raise HTTPException(status_code=404, detail="User not found")
    return users_db[user_id]

@app.post("/users")
def create_user(user: dict):
    user_id = max(users_db.keys()) + 1
    users_db[user_id] = {"id": user_id, **user}
    return users_db[user_id]

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Building the Package

# Install build tools
pip install build twine

# Build the package
python -m build

# This creates:
# - dist/nexarch_sdk-0.1.0-py3-none-any.whl
# - dist/nexarch_sdk-0.1.0.tar.gz

Publishing to PyPI

# Test PyPI (for testing)
twine upload --repository testpypi dist/*

# Production PyPI
twine upload dist/*

Testing Locally

# Install in editable mode
pip install -e .

# Run your FastAPI app
python your_app.py

# Check telemetry
curl http://localhost:8000/__nexarch/telemetry/stats

What Happens After Installation

  1. Middleware Injection: SDK adds middleware to capture every request
  2. Router Auto-Injection: Internal /__nexarch/* endpoints are added
  3. Local Logging: Telemetry is written to JSON file in real-time
  4. No Code Changes: Your existing routes work exactly as before

Security & Privacy

  • No Source Code Access: SDK only observes runtime behavior
  • No Payload Capture: Request/response bodies are never logged
  • Header Sanitization: Sensitive headers (auth, cookies) are redacted
  • Local First: All data stored locally before optional remote sync

Support

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

nexarch_sdk-0.1.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

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

nexarch_sdk-0.1.0-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file nexarch_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: nexarch_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for nexarch_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89d7a88d5c84a94ebe6f2d7d6da6fe4223537cc7f6c21ef485c38473a514f151
MD5 cab80b80dcce8dd6097284d5b42348b9
BLAKE2b-256 4aea7e8a29d04bc37a58207fbdd839c655796457e91d38939259cce0309ad596

See more details on using hashes here.

File details

Details for the file nexarch_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nexarch_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for nexarch_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a82dc9230593458c391a9d4232891be7ed01dee84ab2b70188ef935158437e59
MD5 50ce4d0826e5c1fd0ba4c0e918c9eaeb
BLAKE2b-256 608bf78b562bf09c1bb3ad0c18d52331c859ce85a1eb3a6c7f6d03e977c2f687

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