> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nolano.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Get started with the Nolano Python SDK for easy integration with the Nolano API

The Nolano Python SDK provides a simple and intuitive way to interact with the Nolano API from your Python applications.

<div className="not-prose">
  <div className="my-8 overflow-hidden rounded-2xl border border-gray-200/60 bg-gradient-to-br from-white via-gray-50/50 to-purple-50/30 p-8 shadow-xl shadow-gray-200/20 backdrop-blur-sm dark:border-gray-700/60 dark:from-gray-900 dark:via-gray-800/50 dark:to-purple-900/20 dark:shadow-gray-900/40">
    <div className="flex items-start space-x-6">
      <div className="flex-shrink-0">
        <div className="relative">
          <div className="flex h-16 w-16 items-center justify-center rounded-2xl bg-white dark:bg-gray-800 shadow-lg shadow-purple-500/25 border border-gray-200/60 dark:border-gray-700/60">
            <img src="https://mintcdn.com/nolanoinc/bS158rzJAoPcjh7l/logo/logo.avif?fit=max&auto=format&n=bS158rzJAoPcjh7l&q=85&s=8e9545f6e0e3ab4e4d2a3a082d67e222" alt="Nolano Logo" className="h-10 w-10 dark:hidden" width="419" height="476" data-path="logo/logo.avif" />

            <img src="https://mintcdn.com/nolanoinc/bS158rzJAoPcjh7l/logo/logo.avif?fit=max&auto=format&n=bS158rzJAoPcjh7l&q=85&s=8e9545f6e0e3ab4e4d2a3a082d67e222" alt="Nolano Logo" className="h-10 w-10 hidden dark:block" width="419" height="476" data-path="logo/logo.avif" />
          </div>

          <div className="absolute -right-1 -top-1 h-5 w-5 rounded-full bg-green-500 border-2 border-white dark:border-gray-900">
            <svg className="h-3 w-3 text-white ml-0.5 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
              <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
            </svg>
          </div>
        </div>
      </div>

      <div className="flex-1 min-w-0">
        <div className="flex items-center space-x-3">
          <h3 className="text-xl font-bold text-gray-900 dark:text-white">Nolano Python SDK</h3>

          <span className="inline-flex items-center rounded-full bg-purple-100 px-2.5 py-0.5 text-xs font-medium text-purple-800 dark:bg-purple-900/30 dark:text-purple-300">
            v1.0.0
          </span>
        </div>

        <p className="mt-2 text-base text-gray-600 dark:text-gray-300 leading-relaxed">
          Simple and intuitive Python SDK for the Nolano API. Built for developers who want fast integration with powerful time series forecasting capabilities.
        </p>

        <div className="mt-6 flex flex-wrap gap-3">
          <a href="https://pypi.org/project/nolano/" className="group inline-flex items-center rounded-xl bg-gradient-to-r from-purple-600 to-purple-700 px-6 py-3 text-sm font-semibold text-white shadow-lg shadow-purple-500/25 transition-all duration-200 hover:from-purple-700 hover:to-purple-800 hover:shadow-xl hover:shadow-purple-500/30 hover:-translate-y-0.5 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900">
            <svg className="mr-2 h-4 w-4 transition-transform group-hover:scale-110" fill="currentColor" viewBox="0 0 24 24">
              <path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" />
            </svg>

            Install from PyPI

            <svg className="ml-2 h-4 w-4 transition-transform group-hover:translate-x-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 7l5 5m0 0l-5 5m5-5H6" />
            </svg>
          </a>

          <a href="https://github.com/tejasvaidhyadev/nolano" className="group inline-flex items-center rounded-xl border border-gray-300 bg-white px-6 py-3 text-sm font-semibold text-gray-700 shadow-lg transition-all duration-200 hover:bg-gray-50 hover:border-gray-400 hover:shadow-xl hover:-translate-y-0.5 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 dark:hover:bg-gray-700 dark:hover:border-gray-500 dark:focus:ring-offset-gray-900">
            <svg className="mr-2 h-4 w-4 transition-transform group-hover:scale-110" fill="currentColor" viewBox="0 0 24 24">
              <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
            </svg>

            View on GitHub

            <svg className="ml-2 h-4 w-4 transition-transform group-hover:translate-x-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
            </svg>
          </a>
        </div>

        <div className="mt-4 flex items-center space-x-4 text-xs text-gray-500 dark:text-gray-400">
          <div className="flex items-center space-x-1">
            <div className="h-2 w-2 rounded-full bg-green-500" />

            <span>Active maintenance</span>
          </div>

          <div className="flex items-center space-x-1">
            <svg className="h-3 w-3" fill="currentColor" viewBox="0 0 20 20">
              <path fillRule="evenodd" d="M12.395 2.553a1 1 0 00-1.45-.385c-.345.23-.614.558-.822.88-.214.33-.403.713-.57 1.116-.334.804-.614 1.768-.84 2.734a31.365 31.365 0 00-.613 3.58 2.64 2.64 0 01-.945-1.067c-.328-.68-.398-1.534-.398-2.654A1 1 0 005.05 6.05 6.981 6.981 0 003 11a7 7 0 1011.95-4.95c-.592-.591-.98-.985-1.348-1.467-.363-.476-.724-1.063-1.207-2.03zM12.12 15.12A3 3 0 017 13s.879.5 2.5.5c0-1 .5-4 1.25-4.5.5 1 .786 1.293 1.371 1.879A2.99 2.99 0 0113 13a2.99 2.99 0 01-.879 2.121z" clipRule="evenodd" />
            </svg>

            <span>Latest release</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

## Installation

Install the SDK using pip:

```bash theme={null}
pip install nolano
```

Or install directly from GitHub:

```bash theme={null}
pip install git+https://github.com/tejasvaidhyadev/nolano.git
```

## Quick Start

### Initialize the Client

```python theme={null}
from nolano import Nolano

client = Nolano(api_key="your-api-key-here")
```

### Basic Usage

```python theme={null}
from nolano import Nolano
import pandas as pd

# Initialize the client
client = Nolano(api_key="your_api_key_here")

# Or set environment variable: NOLANO_API_KEY=your_api_key_here
client = Nolano()

# Verify API key (recommended)
verification = client.verify_api_key()
if not verification['valid']:
    print(f"API key issue: {verification['message']}")
    exit(1)

print("✅ API key verified successfully!")

# Prepare your time series data
df = pd.DataFrame({
    'date': pd.date_range(start='2023-01-01', periods=100, freq='D'),
    'sales': [100, 102, 98, 105, 110, 108, 115, 120, 125, 130, 128, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365, 370, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430, 435, 440, 445, 450, 455, 460, 465, 470, 475, 480, 485, 490, 495, 500, 505, 510, 515, 520, 525, 530, 535, 540, 545, 550, 555, 560, 565, 570, 575]
})

# Generate forecast
forecast = client.forecast(
    dataset=df,
    target_col='sales',
    timestamp_col='date',
    forecast_horizon=30,
    data_frequency='Daily'
)

print(f"Forecast: {forecast.median}")
print(f"Lower bound: {forecast.lower_bound}")
print(f"Upper bound: {forecast.upper_bound}")
```

## API Reference

### Constructor Parameters

```python theme={null}
class Nolano:
    def __init__(
        self,
        api_key: str = None,
        model_id: str = "forecast-model-1"
    ):
        """
        Initialize the Nolano client.
        
        Args:
            api_key: Your Nolano API key (optional if NOLANO_API_KEY env var is set)
            model_id: Default model to use for forecasting
        """
```

### Forecast Method

```python theme={null}
def forecast(
    self,
    dataset: pd.DataFrame,
    target_col: str,
    timestamp_col: str,
    forecast_horizon: int,
    data_frequency: str = "Daily",
    forecast_frequency: str = None,
    confidence: float = 0.95,
    model_id: str = None
) -> NolanoForecast:
    """
    Generate time series forecasts from a pandas DataFrame.
    
    Args:
        dataset: pandas DataFrame with time series data
        target_col: Column name containing values to forecast
        timestamp_col: Column name containing timestamps
        forecast_horizon: Number of periods to forecast
        data_frequency: Data frequency (Daily, Hourly, Weekly, etc.)
        forecast_frequency: Forecast frequency (optional, defaults to data_frequency)
        confidence: Confidence level for prediction intervals
        model_id: Model to use (optional, uses default)
    
    Returns:
        NolanoForecast object with prediction data
    """
```

## Error Handling

The SDK provides helpful error messages for common issues:

```python theme={null}
# Verify API key before making requests
try:
    result = client.verify_api_key()
    if not result['valid']:
        print(f"API key verification failed: {result['message']}")
        # Handle invalid API key case
        exit(1)
    
    print("API key verified successfully!")
    
    # Proceed with forecasting
    forecast = client.forecast(
        dataset=df,
        target_col='sales',
        timestamp_col='date',
        forecast_horizon=30,
        data_frequency='Daily'
    )
    
except ValueError as e:
    print(f"Parameter error: {e}")
except KeyError as e:
    print(f"Column not found: {e}")
except Exception as e:
    print(f"API error: {e}")
```

## Advanced Examples

### Using Different Models

```python theme={null}
# List available models
models = client.list_models()
for model in models:
    print(model)

# Use a specific model
forecast = client.forecast(
    dataset=df,
    target_col='sales',
    timestamp_col='date',
    forecast_horizon=30,
    data_frequency='Daily',
    model_id='forecast-model-2'  # Use alternative model
)
```

### Data Validation

```python theme={null}
# Validate your data before forecasting
validation = client.validate_data(
    dataset=df,
    target_col='sales',
    timestamp_col='date'
)

if validation['valid']:
    print("Data is valid!")
    print(f"Stats: {validation['stats']}")
else:
    print("Data issues found:")
    for warning in validation['warnings']:
        print(f"- {warning}")
```

### Working with Forecast Results

```python theme={null}
# Access forecast data
forecast.forecast_timestamps  # List of forecast timestamp strings
forecast.median              # List of median forecast values
forecast.lower_bound         # List of lower confidence bound values
forecast.upper_bound         # List of upper confidence bound values

# Convert to DataFrame
df = forecast.to_dataframe()

# Evaluate forecast accuracy
actual_values = [105, 110, 108, 115, 120]  # Actual values for forecast period
metrics = forecast.evaluate(actual_values)
print(f"MAE: {metrics['mae']:.2f}")
print(f"WAPE: {metrics['wape']:.2f}%")
```

## Supported Frequencies

The Nolano API supports the following time series frequencies:

* `Seconds` - Second-level data
* `Minutes` - Minute-level data
* `Hours` - Hourly data
* `Daily` - Daily data
* `Weekly` - Weekly data
* `Monthly` - Monthly data
* `Quarterly` - Quarterly data
* `Yearly` - Annual data

## Environment Variables

For production applications, use environment variables:

```python theme={null}
import os

# Set your API key
export NOLANO_API_KEY=your_api_key_here

# In your code
client = Nolano()  # Will automatically use NOLANO_API_KEY environment variable
```

## Examples

Check out the examples directory in the [GitHub repository](https://github.com/tejasvaidhyadev/nolano) for complete usage examples:

* `examples/verify_api_key.py` - Quick API key verification script
* `examples/nolano_example.py` - Comprehensive usage examples with API verification
* `examples/nolano-forecasting-example.ipynb` - Jupyter notebook tutorial

### Quick API Key Test

To quickly verify your API key is working:

```python theme={null}
from nolano import Nolano

client = Nolano()
result = client.verify_api_key()

if result['valid']:
    print("✅ API key is valid!")
else:
    print(f"❌ Issue: {result['message']}")
```

## Next Steps

* Visit the [GitHub repository](https://github.com/tejasvaidhyadev/nolano) for the latest updates and examples
* Explore the [API Reference](/api-reference/introduction) for detailed endpoint documentation
* Get support by opening an issue on [GitHub](https://github.com/tejasvaidhyadev/nolano/issues) or contacting [hello@nolano.ai](mailto:hello@nolano.ai)
