San Francisco has often been been overrepresented at the top levels of the state and national capitals. Still, there has never been a moment quite like this, when leaders who came from the city by the bay have assumed roles as speaker of the House, both U.S. senators and governor of the nation’s most populous state, along with the statewide offices of lieutenant governor, controller and treasurer.

Oh, and one of those senators, Kamala Harris, just happened to be the No. 1 “get” last week for all the coveted shows — from “The View” to Stephen Colbert to NPR to “Good Morning America” — as she embarked on a tour for her new memoir (“The Truths We Hold: An American Journey”) in advance of the expected announcement of her 2020 presidential candidacy.

So what is it about California’s fourth-largest city that produces such extraordinary depth and diversity of leadership skill? It’s not as if they come from a singular mold. They’re all Democrats, of course, but their styles could not be more different. Gov. Gavin Newsom has the movie-star looks and a desire to dissect and discuss data to the point of audience exhaustion; House Speaker Nancy Pelosi has a force of personality, with an ability to pivot from charm to steeliness as circumstances merit, which makes her a formidable fundraiser and world-class legislative tactician; Harris has a touch of all those qualities along with a prosecutor’s focus and an aura of destiny that put her in the conversation for president from the day she was sworn into the Senate just two years ago.

What they all have in common is having been tested in San Francisco.

“San Francisco is a rough political environment,” said state Sen. Scott Wiener, D-San Francisco. “Getting elected to the San Francisco Board of Supervisors is much harder than getting elected to Congress in many parts of the country.”

And why is that? The answer may be evident on the streets, where an elected official has nowhere to hide, even in a city of about 860,000.

“One of the wonderful things about San Francisco is that the residents of our city are so deeply engaged,” Wiener added. “When you represent all or part of San Francisco, you can’t B.S. your constituents. People watch, people, know, people understand what’s going on.”

Nathan Ballard, a prominent strategist who served as communications director for Newsom when he was mayor, cited three factors for San Franciscans’ elevation in Sacramento and Washington: a highly engaged electorate, a “robust media culture” and an “unusually competitive election process” that can be grueling for even the lower-level offices.

“They say that San Francisco’s sourdough is the best in the world because the foggy air does something special to the yeast,” Ballard said. “You can take the same yeast to Seattle, Buffalo or Portland but it won’t make the same sourdough. The same can be said of our politics: There is something in the air that gives our political leaders great strength.”

One of those elements is mentorship. The late Rep. Phil Burton, a master of machine politics, was a powerhouse in both the city and nation’s capital during his tenure in Congress from 1964 to 1983. He had a knack for spotting and coaching leaders, including his brother John (who later became state Senate leader) and Willie Brown (state Assembly speaker, then mayor).

The Burton-Brown machine changed the dynamic of state politics, pulling the balance of clout northward. Its influence resonates to this day with Brown’s role as “the nursing father” in “the new generation of leaderings including California’s governor (Newsom), its junior senator (Harris) and the mayor of San Francisco (London Breed),” observed James Taylor, professor of political science at the University of San Francisco.

“It is precisely because of the legacy and foundation of Phil Burton’s Democratic machine that San Francisco dominates the state’s national and key statewide elected offices,” Taylor said.

Or, as political consultant Mary Hughes put it, “In Los Angeles you have the entertainment industry ... in San Francisco our industry is politics.” She attributed the city’s preoccupation with politics, in part, to the “intensity and density” of talent — along with the city’s image as a welcoming place for experimentation and acceptance of the unorthodox.

“There is a sizzle and energy and excitement in San Francisco that attracts people who are doers,” said Hughes, who has been building an impressive network of her own in recruiting and grooming female candidates. “If we’re talking romantically about American political ambition, San Francisco is a place where people cluster who have different ideas, new ideas.”

And they are willing to export them, most famously in the Valentine’s Day revolution of 2004, when, under Newsom, City Hall began to issue same-sex marriage licenses in open defiance of state law.

As he moved from City Hall to the state Senate in 2016, ex-Supervisor Wiener said he was reminded of expectation of a San Francisco legislator by his predecessor Mark Leno. “The beauty of representing San Francisco in Sacramento is that you have the space and the latitude to push the envelope,” Wiener said he was advised. “Not everyone here has that. Our constituents demand it.”

Fox News and other right-wing outlets might like to caricature San Francisco as “Left Coast City,” and same-sex-marriage champion Newsom as its poster child, but the fact is that he was the centrist in every race he ran until he went statewide. As mayor, Newsom’s willingness to take into account the legitimate concerns for the business environment put him in constant conflict with a progressive faction on the Board of Supervisors that resented his charisma and resisted his policy initiatives at almost every turn.

“This brutal ‘Game of Thrones’-style culture produces some unusually strong political leaders,” Ballard said. “Gavin Newsom went through hell and back when he was mayor. And that’s a big reason that he is arguably the best political athlete on the scene today. If you can make it in San Francisco, you can make it anywhere.”

Newsom may have moved from San Francisco, to Kentfield with his young family, and then to the governor’s mansion in Sacramento, but there is no escaping the influence of the city on honing his political acumen and establishing his national stature. Harris, the former San Franciso district attorney and twice-elected state attorney general, now lives in Los Angeles with her husband and stepchildren, but she surely will be cast as an icon of “San Francisco values,” by critics and admirers alike, in a presidential campaign.

Lt. Gov. Eleni Kounalakis, state Treasurer Fiona Ma and state Controller Betty Yee all have San Francisco pedigree — and each is a possible contender for other statewide offices.

It’s worth noting that the former governor, Jerry Brown, had San Francisco roots of his own. He was by the side of his father, Pat Brown, in a campaign for San Francisco district attorney in 1943 with the slogan, “Crack down on crime, elect Brown this time.” The elder Brown won an upset victory that year and was elected governor in 1958. Young Jerry was “raised in the rough and tumble of San Francisco political campaigns,” Ballard reminded, calling him “the Dutch Newsom of his time,” a reference to the new governor’s 2-year-old son who stole the spotlight at Monday’s inaugural.

So keep an eye on that kid on the stage; the San Francisco magic tends to transcend generations.

John Diaz is The San Francisco Chronicle’s editorial page editor. Email: jdiaz@sfchronicle.com Twitter: @JohnDiazChron