# FFIEC Call Reports Library

A Python library for downloading and processing FFIEC Call Reports. This library provides a simple interface to download call reports from the FFIEC's Central Data Repository (CDR) and process them into a usable format.

## Installation

```bash
pip install ffiec-call-reports
```

## Quick Start

```python
from ffiec_call_reports import FFIECClient
from datetime import datetime

# Initialize client
client = FFIECClient(username="your_username", passphrase="your_passphrase")

# Download a single call report
report = client.get_call_report(
    rssd_id=1842065,
    period_end_date="2019/03/31"
)

# Get specific metrics
total_assets = report.get_metric("RCFD2170")  # Total Assets
total_loans = report.get_metric("RCFD1400")   # Total Loans

# Download multiple reports
reports = client.get_multiple_call_reports(
    rssd_ids=[1842065, 1842066],
    period_end_date=datetime(2019, 3, 31)
)

# Save to CSV
report.to_csv("call_report.csv")
```

## Features

- Download call reports for single or multiple institutions
- Process XBRL data into pandas DataFrames
- Map metric IDs to human-readable descriptions
- Extract specific metrics easily
- Save reports to CSV format
- Streamlit web interface for easy access

## Web Interface

The library includes a Streamlit web interface for easy access. To run it:

```bash
streamlit run src/app_streamlit.py
```

## Usage Examples

### Basic Usage

```python
from ffiec_call_reports import FFIECClient

# Initialize client
client = FFIECClient(username="your_username", passphrase="your_passphrase")

# Download a report
report = client.get_call_report(1842065, "2019/03/31")

# Get the data as a DataFrame
df = report.to_dataframe()
```

### Working with Multiple Reports

```python
from ffiec_call_reports import FFIECClient, get_mapping_dict, apply_mapping
import pandas as pd

# Initialize client
client = FFIECClient(username="your_username", passphrase="your_passphrase")

# Download multiple reports
reports = client.get_multiple_call_reports(
    rssd_ids=[1842065, 1842066, 1842067],
    period_end_date="2019/03/31"
)

# Combine all reports
all_data = pd.concat([report.to_dataframe() for report in reports])

# Apply mapping
mapping_dict = get_mapping_dict()
mapped_data = apply_mapping(all_data, mapping_dict)
```

### Extracting Specific Metrics

```python
# Get a single metric
total_assets = report.get_metric("RCFD2170")

# Get multiple metrics
metrics = report.get_metrics([
    "RCFD2170",  # Total Assets
    "RCFD1400",  # Total Loans
    "RCFD1410"   # Commercial & Industrial Loans
])
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the LICENSE file for details.