# Sunrise Sunset Times Api (`kawsar/sunrise-sunset-times-api`) Actor

Extract precise sunrise, sunset, solar noon, and twilight times for multiple coordinates and date ranges. Input your locations and dates, then export clean results as JSON, CSV, or Excel for travel planning, photography shoots, outdoor events, or scheduling.

- **URL**: https://apify.com/kawsar/sunrise-sunset-times-api.md
- **Developed by:** [Kawsar](https://apify.com/kawsar) (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

## Sunrise & Sunset Time Extractor

<p align="center">
  <img src="https://imgur.com/vlvhp7j.png" alt="Sunrise Sunset Times" style="max-width:100%; border-radius:14px; width:680px;" />
</p>

Need to calculate exact daylight hours, twilight phases, and solar noon for multiple coordinates across a specific date range? This actor makes it super simple to pull comprehensive daylight and twilight datasets in bulk without any complex setup. Just feed it a list of coordinates and your date range, and it handles the rest, outputting clean rows ready for export as JSON, CSV, or Excel.

### Use Cases

- **Travel planning:** Double-check sunrise and sunset times for every stop on an upcoming trip before finalizing your itinerary.
- **Photo & film shoots:** Accurately track civil twilight beginnings and ends across multiple days for outdoor production locations.
- **Outdoor events:** Quickly check sunset times and day length for venues without having to manually look up dates one by one.
- **Field work:** Batch coordinate checks so field crews know precisely when nautical twilight starts.
- **Regular schedules:** Set up a scheduled run to keep a fresh, dated log of daylight metrics over time.

***

### What Data Does This Actor Extract?

Each row in your dataset represents a single location for a specific date, packed with precise solar metrics:

| Field | Meaning |
| :--- | :--- |
| `latitude`, `longitude`, `queryDate` | The specific coordinates and date requested |
| `sunrise`, `sunset`, `solar_noon` | Key daily solar timestamps |
| `day_length` | Total daylight duration in seconds |
| `civil_twilight_begin`, `civil_twilight_end` | Civil twilight window |
| `nautical_twilight_begin`, `nautical_twilight_end` | Nautical twilight window |
| `astronomical_twilight_begin`, `astronomical_twilight_end` | Astronomical twilight window |
| `tzid` | Timezone identifier |
| `scrapedAt` | Timestamp of when the data was captured |
| `error` | Populated only if a specific request encountered an issue |

***

### Input Configuration

Here is an example input configuration to get you started:

```json
{
  "mode": "times",
  "locations": [
    { "lat": 40.7128, "lng": -74.006 },
    { "lat": 51.5074, "lng": -0.1278 }
  ],
  "startDate": "2026-10-12",
  "days": 2,
  "maxItems": 100,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30,
  "proxyConfiguration": { "useApifyProxy": false }
}

```

#### Parameter Reference

- **`mode`**: Currently set to `"times"` for day length and solar schedules.
- **`locations`**: An array of latitude and longitude coordinate objects you want to query.
- **`startDate`**: Starting date in `YYYY-MM-DD` format (or `"today"`).
- **`days`**: Number of consecutive days to check per location (up to 366).
- **`maxItems`**: The maximum number of rows to collect (defaults to 100, capped at 1,000).
- **`timeoutSecs`**: Overall run timeout limit in seconds.
- **`requestTimeoutSecs`**: Timeout limit for individual requests.
- **`proxyConfiguration`**: Optional proxy settings (defaults to no proxy).

***

### How It Runs & Limits

The actor processes requests systematically—one location and date at a time—with a steady pacing to keep things smooth and reliable. If a temporary network glitch or timeout occurs, it automatically retries a few times before logging an error row and moving forward so your entire run doesn't fail over a single bad coordinate.

Duplicate location-date pairs are automatically filtered out, and your resulting datasets can easily be exported to JSON, CSV, or Excel directly from your Apify console.

***

### Frequently Asked Questions

#### How many rows can a single run save?

The default cap is 100 rows, with a hard maximum of 1,000 rows per run. Each location-date combination counts as one individual row.

#### What happens if a coordinate or date is invalid?

The actor handles it gracefully by creating an error row containing details about the failure, allowing the rest of your batch to finish running smoothly.

#### Can I export the results to CSV or Excel?

Yes! Apify datasets support native exports to JSON, CSV, and Excel formats.

#### Trademark Notice

Sunrise Sunset Times and related names, logos, and trademarks belong to their respective owners. Their use in this documentation is solely to identify the source of the data and does not imply affiliation, sponsorship, endorsement, or partnership.

#### Disclaimer

Disclaimer: This Actor is an independent tool and is not affiliated with, endorsed by, sponsored by, or otherwise officially associated with Sunrise Sunset Times or its owners. All data is collected from publicly available sources. Users are responsible for complying with the source's terms of use, rate limits, and attribution or licensing requirements.

#### Is web scraping legal?

This Actor only collects publicly available data from Sunrise Sunset Times, mostly through its public API or feed, without logging in or bypassing any access controls. Scraping public data is generally legal, but how you use it matters:

- **Personal data:** If the results include personal data (for example names, emails, or profile details), laws such as the GDPR in the EU and the CCPA in California may apply. Only collect and store personal data when you have a legitimate reason.
- **Copyright:** Some content (articles, images, descriptions) may be protected by copyright. Do not republish full copyrighted content without permission.
- **Terms of use:** Respect the source's terms, stated rate limits, and any attribution or non-commercial-use requirements listed in the Limits and terms section above.
- **Legal advice:** This is general information, not legal advice. If you're unsure, consult a lawyer.

To learn more, read Apify's guide: [Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/)

# Actor input Schema

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

Run mode. times requests sunrise, sunset, solar noon, day length, and twilight for each location and date.

## `locations` (type: `array`):

List of coordinate objects. Each object needs numeric lat and lng. Latitude must be between -90 and 90. Longitude must be between -180 and 180. Default is New York City.

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

First calendar day to request, as YYYY-MM-DD in UTC. Use today to start from the current UTC date.

## `days` (type: `integer`):

How many consecutive UTC dates to request from the start date, including the start date. One API call is made per location and date. Hard maximum is 366.

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

Maximum dataset rows for this run, including error rows. Values above 1000 are clamped to 1000.

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

Stop scheduling new requests after this many seconds. In-flight work can finish. Default is 300. Maximum is 3600.

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

HTTP timeout for each call to the sunrise-sunset API. Default is 30 seconds.

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

Optional proxy. Leave Apify Proxy off. The public API does not require a proxy for normal volumes, and proxies must not be used to get around the source rate limits.

## Actor input object example

```json
{
  "mode": "times",
  "locations": [
    {
      "lat": 40.7128,
      "lng": -74.006
    }
  ],
  "startDate": "2026-10-12",
  "days": 1,
  "maxItems": 100,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

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

No description

## `datasetUrl` (type: `string`):

No description

# 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 = {
    "locations": [
        {
            "lat": 40.7128,
            "lng": -74.006
        }
    ],
    "startDate": "today",
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("kawsar/sunrise-sunset-times-api").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 = {
    "locations": [{
            "lat": 40.7128,
            "lng": -74.006,
        }],
    "startDate": "today",
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("kawsar/sunrise-sunset-times-api").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 '{
  "locations": [
    {
      "lat": 40.7128,
      "lng": -74.006
    }
  ],
  "startDate": "today",
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call kawsar/sunrise-sunset-times-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kawsar/sunrise-sunset-times-api"
        }
    }
}
```

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/pSNaIIvglyDEK4Pml/builds/0ExctQfPTjNrQEfcB/openapi.json
