# Us Treasury Yield Curve Scraper (`real-estate-api/us-treasury-yield-curve-scraper-202610120341`) Actor

US Treasury Yield Curve Scraper is a Python tool designed to extract daily constant-maturity market yields, tenors (1-month to 30-year), and yield spreads from the U.S. Department of the Treasury. It exports structured macroeconomic data into clean CSV or JSON format.

- **URL**: https://apify.com/real-estate-api/us-treasury-yield-curve-scraper-202610120341.md
- **Developed by:** [real-estate-api](https://apify.com/real-estate-api) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.99 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### US Treasury Yield Curve Scraper — Daily Treasury Par Yield Curve Rates

### Overview

US Treasury Yield Curve Scraper collects daily Treasury par yield curve rates published by the U.S. Department of the Treasury. It organizes the available historical rates into structured records, with one row per curve date and columns for standard maturities ranging from one month to 30 years.

Choose yearly CSV collection, monthly XML collection, or both modes to build a historical interest-rate dataset for financial analysis, economic research, yield curve visualization, and model development. Export the results as JSON, CSV, or Excel through the Apify dataset.

### Features

- **Historical rate collection:** Collect published Treasury par yield curve observations by year or month.
- **Multiple collection modes:** Select yearly CSV, monthly XML, or both.
- **Standard maturity columns:** Capture available short-term and long-term Treasury yields.
- **Date filtering:** Keep observations on or after a specified start date.
- **Duplicate prevention:** Avoid duplicate curve dates within the same collection mode.
- **Structured output:** Store each observation as a flat dataset row.
- **Scheduled updates:** Refresh the dataset periodically to capture newly published observations.
- **Spreadsheet exports:** Download the collected records in JSON, CSV, or Excel format.

### Use Cases

- **Historical curve archives:** Preserve yearly Treasury yield observations for financial modeling.
- **Maturity comparisons:** Chart 2-year, 10-year, and 30-year yields from one dataset.
- **Monthly updates:** Collect a specific month when only recent observations are needed.
- **Financial research:** Export Treasury rates for economic analysis and reporting.
- **Model development:** Prepare structured interest-rate data for yield curve models and forecasting workflows.
- **Scheduled snapshots:** Build a growing historical dataset through recurring collection runs.

### Input Parameters

| Parameter | Type | Default | Description |
|---|---|---|---|
| `mode` | String | `csv` | Collection mode: `csv` for yearly files, `xml` for monthly files, or `both` for both formats. |
| `years` | Array of integers | `[2025]` | Calendar years to collect in CSV mode. |
| `months` | Array of strings | `["202501"]` | Months to collect in XML mode, formatted as `YYYYMM`. |
| `rateType` | String | `daily_treasury_yield_curve` | Identifies the daily par yield curve series. |
| `startDate` | String | Empty | Optional earliest observation date. Accepts `YYYY-MM-DD` or `MM/DD/YYYY`. |
| `maxItems` | Integer | `100` | Maximum number of successful rows to save. Hard maximum: 1,000. |
| `requestDelaySecs` | Number | `1` | Minimum delay between requests, in seconds. |
| `timeoutSecs` | Integer | `300` | Maximum run duration. Previously saved rows are retained when the run stops. |
| `requestTimeoutSecs` | Integer | `30` | Maximum wait for an individual response. |

#### Example Input

**1. Collect the 2025 yearly yield curve**

```json
{
  "mode": "csv",
  "years": [2025],
  "months": ["202501"],
  "rateType": "daily_treasury_yield_curve",
  "startDate": "",
  "maxItems": 100,
  "requestDelaySecs": 1,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30
}
```

**2. Collect a specific month**

```json
{
  "mode": "xml",
  "years": [],
  "months": ["202501"],
  "rateType": "daily_treasury_yield_curve",
  "startDate": "",
  "maxItems": 100,
  "requestDelaySecs": 1,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30
}
```

**3. Collect both yearly and monthly data**

```json
{
  "mode": "both",
  "years": [2024, 2025],
  "months": ["202501", "202502"],
  "rateType": "daily_treasury_yield_curve",
  "startDate": "2025-01-01",
  "maxItems": 1000,
  "requestDelaySecs": 1,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30
}
```

For `both` mode, yearly files are processed before monthly files. Select the years and months you want to collect to avoid unnecessary requests.

### What Data Does This Actor Extract?

Each successful record represents a Treasury yield curve observation for one date. The maturity columns contain rates expressed as percentages, following the source's published field names.

#### Extracted Data Fields

| Field | Description |
|---|---|
| `Date` | Observation date, generally formatted as `MM/DD/YYYY`. |
| `1 Mo` | One-month Treasury yield, as a percentage. |
| `1.5 Month` | One-and-a-half-month yield, when available in the source file. |
| `2 Mo` | Two-month Treasury yield, as a percentage. |
| `3 Mo` | Three-month Treasury yield, as a percentage. |
| `4 Mo` | Four-month Treasury yield, as a percentage. |
| `6 Mo` | Six-month Treasury yield, as a percentage. |
| `1 Yr` | One-year Treasury yield, as a percentage. |
| `2 Yr` | Two-year Treasury yield, as a percentage. |
| `3 Yr` | Three-year Treasury yield, as a percentage. |
| `5 Yr` | Five-year Treasury yield, as a percentage. |
| `7 Yr` | Seven-year Treasury yield, as a percentage. |
| `10 Yr` | Ten-year Treasury yield, as a percentage. |
| `20 Yr` | Twenty-year Treasury yield, as a percentage. |
| `30 Yr` | Thirty-year Treasury yield, as a percentage. |
| `mode` | Collection format associated with the row: `csv` or `xml`. |
| `scraped_at` | UTC timestamp indicating when the record was saved. |

Available maturity columns may vary by source file and observation period. Some values may be absent when the source does not provide them.

#### Example Output

```json
{
  "Date": "12/31/2025",
  "1 Mo": 3.74,
  "1.5 Month": 3.75,
  "2 Mo": 3.67,
  "3 Mo": 3.67,
  "4 Mo": 3.63,
  "6 Mo": 3.59,
  "1 Yr": 3.48,
  "2 Yr": 3.47,
  "3 Yr": 3.55,
  "5 Yr": 3.73,
  "7 Yr": 3.94,
  "10 Yr": 4.18,
  "20 Yr": 4.79,
  "30 Yr": 4.84,
  "mode": "csv",
  "scraped_at": "2026-10-12T00:00:00+00:00"
}
```

The values above illustrate the output structure. Actual records depend on the selected period and the Treasury data available at collection time.

### Working with Your Dataset

Once collection finishes, open the Apify dataset and select your preferred export format.

- **JSON:** Suitable for Python data processing, structured storage, and integration into analytical workflows.
- **CSV:** Useful for Pandas, spreadsheet applications, and statistical analysis.
- **Excel:** Convenient for reviewing observations, preparing reports, and sharing results.

For example, you can use the `Date`, `2 Yr`, `10 Yr`, and `30 Yr` columns to create maturity comparison charts or calculate yield spreads. Always check for missing observations before performing calculations.

### Important Notes

- The default mode is `csv`, with the year set to 2025.
- CSV mode collects yearly files; XML mode collects monthly files.
- The `both` mode processes yearly files before monthly files.
- The `startDate` parameter filters observations to dates on or after the specified date.
- The maximum number of saved successful rows is 1,000 per run.
- The default row limit is 100. A yearly file may be downloaded in full even when the configured row limit is small.
- Treasury data files can take several seconds to respond. Longer collection periods may require additional run time.
- Requests are processed sequentially, with a minimum delay between requests.
- Duplicate dates within the same collection mode are skipped.
- Data availability depends on the publication schedule and the records available when the actor runs.
- The maturity columns follow the source's published names; available columns can differ between historical files.
- The actor is intended for collecting published observations, not for predicting future interest rates or providing investment advice.

### FAQ

**What is the Treasury par yield curve?**

It is a series of Treasury yields across different maturities, published for financial analysis and reference. The observations can be used to compare short-term and long-term interest rates.

**What is the difference between CSV and XML modes?**

CSV mode collects yearly files, while XML mode collects monthly records. The `both` mode processes the selected yearly files first and then the selected monthly files.

**How fresh is the collected data?**

The dataset reflects the information published by the Treasury when the collection runs. A scheduled run can help capture new observations as they become available.

**Why is collecting a year sometimes slow?**

Yearly files can take several seconds to download and process. The actor uses sequential requests and a configurable per-request timeout to accommodate slower responses.

**Can I collect only recent observations?**

Yes. Set `startDate` to the earliest date you want to keep and select the appropriate years or months.

**Why are some yield values missing?**

The available maturity columns and values can vary across source files and observation dates. Missing values should be handled appropriately before analysis.

**Can I export the results to Excel?**

Yes. The completed dataset can be downloaded as JSON, CSV, or Excel.

**Can I use the data for financial models?**

The dataset can support historical analysis and model development. Validate the observations, account for missing data, and ensure that your model is appropriate for your intended use.

### Disclaimer

This actor is an independent data-collection tool and is not affiliated with, endorsed by, sponsored by, or officially associated with the U.S. Department of the Treasury. The collected information is provided for research and analytical purposes. Users are responsible for assessing the suitability of the data for their intended applications. The dataset is not investment advice or a recommendation to buy or sell financial instruments.

### Is Web Scraping Legal?

Collecting information that is already public is generally legal. Scraping is not the same thing as hacking, and there is no single law that bans it. The limits are the usual ones: do not break into accounts, do not take private or confidential data, and be careful with personal data and copyrighted works. A site's terms can also restrict how you access it. Facts such as a public name, price, or rating are not the same thing as republishing someone's article or photo.

This actor collects information from public pages. It does not log in and it does not bypass access controls.

For a longer explanation, see Apify's article [Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/).

# Actor input Schema

## `mode` (type: `string`):

csv downloads one Treasury par yield curve CSV per year. xml downloads the Atom XML feed for each YYYYMM month. both runs the CSV years first, then the XML months.

## `years` (type: `array`):

Calendar years for the CSV mode, as a JSON array of integers. Each year is one request to the daily par yield curve CSV. Ignored when mode is xml.

## `months` (type: `array`):

Months for the XML mode, one YYYYMM value per line, such as 202501. Each month is one request to the daily treasury yield curve XML feed. Ignored when mode is csv.

## `rateType` (type: `string`):

Treasury series id. Only daily_treasury_yield_curve is requested. Daily bill rates, the real yield curve, and the long-term rate are not called.

## `startDate` (type: `string`):

Optional inclusive filter. Keep curve dates on or after this day. Accepts YYYY-MM-DD or MM/DD/YYYY. Leave empty to keep every date in the downloaded files.

## `maxItems` (type: `integer`):

Maximum successful yield rows to save this run. Hard cap is 1000. Error rows do not count toward this limit.

## `requestDelaySecs` (type: `number`):

Seconds to wait between Treasury requests. Minimum is 1 so the slow CSV and XML files stay sequential.

## `timeoutSecs` (type: `integer`):

Stop the run after this many seconds and keep rows already collected. Default 300. Maximum 3600.

## `requestTimeoutSecs` (type: `integer`):

How long to wait for one Treasury response before treating that call as failed. Default 30 seconds. The CSV and XML files often take 10 to 20 seconds.

## `proxyConfiguration` (type: `object`):

Optional proxy for home.treasury.gov requests. Leave useApifyProxy off. The public yield files do not need a proxy.

## Actor input object example

```json
{
  "mode": "csv",
  "years": [
    2024,
    2025
  ],
  "months": [
    "202501",
    "202502"
  ],
  "rateType": "daily_treasury_yield_curve",
  "startDate": "2025-01-02",
  "maxItems": 100,
  "requestDelaySecs": 1,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `dataset` (type: `string`):

Default dataset of daily treasury par yield curve rows.

## `datasetItems` (type: `string`):

JSON items from the default dataset.

## `overview` (type: `string`):

Table of curve dates and the main tenors.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "years": [
        2025
    ],
    "months": [
        "202501"
    ],
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("real-estate-api/us-treasury-yield-curve-scraper-202610120341").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "years": [2025],
    "months": ["202501"],
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("real-estate-api/us-treasury-yield-curve-scraper-202610120341").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "years": [
    2025
  ],
  "months": [
    "202501"
  ],
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call real-estate-api/us-treasury-yield-curve-scraper-202610120341 --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,real-estate-api/us-treasury-yield-curve-scraper-202610120341"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/HxRT24OYELAwGQk5m/builds/AgQjqdY1GJt9ujHS5/openapi.json
