Best and cheap RTC for ESP32

Hello! Could you please suggest which RTC (Real-Time Clock) I should use with the ESP32? Which are widely used, Chea,p, and can be easily programmed with MicroPython or have readily available libraries? I'm planning to design a PCB for this, so I'm not looking for an RTC module.

Choose the one that meets all of your specifications at the lowest cost.

DS3231 is a good choice. If you will be network attached use the internal RTC and update it periodically with NTP.

The DS3231SN NOT M (Inacurate) is as close to an industry standard as it gets. You can get the raw chip from Aliexpress for $ 0.865 USD each in quantities of 10 for $8.65. There are many libraries for this chip, just search the library manager for 3231. Check a few libraries to get the one that best suits your needs.
https://bitl.to/4VV5 may not work
https://www.aliexpress.com/item/1005004427508473.html

You probably know this, but it's worth mentioning just in case you don't know. If your ESP32 has an internet connection, you can get the time from the internet using NTP. The time will then be maintained accurately without using an external RTC.

I know this can be done if using Arduino/C/C++. But are similar functions available when coding in microPython? I never used it myself.

Good catch. I forgot it was a microPython use case. I've never used it either. It seems it is supported.

Note however that the DS3231SN is a 16-pin SO part, whereas the DS3231M also comes in an 8-pin SO package.

Forget about a RTC if you have internet near.
NTP (internet time) only needs a few lines of code, and keeps time within 2 seconds.
It also does automatic DST (daylight savings)
Example.

#include <WiFi.h>  // ESP32
unsigned long prevTime;
time_t now;  // holds epoch
tm tm;       // time struct

void setup() {
  Serial.begin(115200);
  WiFi.begin("SSID", "PASS"); // WiFi credentials
  configTzTime("CET-1CEST,M3.5.0,M10.5.0/3", "at.pool.ntp.org");  // https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
}

void loop() {
  time(&now);
  if (now != prevTime) {     // if time has changed
    prevTime = now;          // remember
    localtime_r(&now, &tm);  // convert epoch to local time
    printf("%02u:%02u:%02u\n", tm.tm_hour, tm.tm_min, tm.tm_sec);
  }
}

Defaults to 3-hourly NTP updates.
More time elements are available. See this page.
Leo..

Despite the advice of many helpers here, even using NTP, I suggest you use an RTC anyway.
IMHO, the best way to address this timing problem is to use the NTP to synchronize the RTC, and to use the RTC when the Internet is unavailable.

Depends on the application. My indoor ESP32 clock will keep time within a few seconds when internet fails for hours or even days. I don't want the hassle of adding a RTC, or adjusting it twice a year, and replacing the battery every five years. My clock has no buttons or access lid.
Leo..

If your ESP32 has no battery, how does it keep time when the mains drops?
OK, maybe there is no need to know the time when there is no mains.
Or perhaps you use your cell phone for that.
All in all, you're right. It depends on the application!

In my scenario, there will be no internet access in some industrial areas. Therefore, I can't rely on Wi-Fi. I plan to use an external Real-Time Clock (RTC) with a coin cell battery to keep track of time in case there is a loss of main power and Wi-Fi.

I think DS3231 will be the best choice. Introduction to DS3231 - The Engineering Projects
DS3231 is a low-cost real-time clock (RTC), which has an integrated temperature-compensated crystal oscillator (TCXO) and I2C working protocol. It also has a backup battery, which provides supply when the main supply is cut off. It is available in 16 pins, 300 mil SO package. This RTC module maintains seconds, minutes, hours, dates, months and yearly information. It changes to date and time at the end of the month automatically including corrections for the leap year.