Low- and middle-income home buyers who enter a lottery this month could win up to $375,000 toward the purchase of a house or condo in San Francisco. The catch: When they sell the home, they must repay the assistance plus a prorated share of any appreciation.

The deadline for entering the city’s Downpayment Loan Assistance Program is July 31, but entrants must first take a home buyer education workshop and get prequalified for a mortgage from a participating lender.

They cannot have owned a home in the past three years and can’t make more than 175 percent of the area’s median income for their household size. A one-person household, for example, could earn up to $145,100 while a four-person one could make up to $207,200.

It’s one of the few government housing programs open to the “missing middle,” people who earn too much to qualify for a below-market-rate home and too little to afford a market-rate one.

“I understand why cities like San Francisco do this. It is important to keep the middle class, the central workforce, teachers, in your city,” said Carol Galante, director of UC Berkeley’s Terner Center for Housing Innovation. “Homeownership is the best inoculation against displacement and gentrification in these neighborhoods.”

Buyers don’t have to live in San Francisco to enter the lottery, but they have to purchase a market-rate home in the city and live in it. They must put up at least 5 percent of the purchase price and get a mortgage for at least half the purchase price. They can’t buy a home that has more bedrooms than they have family members, but there is no limit on the price.

The down-payment assistance is a no-interest, 30-year loan that requires no monthly payments. It’s due when the owner sells, moves, transfers title or decides to repay it. At that point, the owner pays the original loan amount and a proportionate share of any increase in the home’s value (determined by the sales price or an appraisal).

A buyer who borrowed $333,000 from the program to buy a $1 million home would owe one-third of any appreciation because the loan was one-third of the purchase price. If they later sold it for $1.5 million, they’d owe the city $500,000 —the original $333,000 plus a third of the gain.

The city has $15.2 million available this year, which could fund at least 40 loans. Last year, it had about $10 million available and funded 26 loans, with four more pending. The program received about 200 applications, so the odds of winning were almost 7-1 — much better than other city housing programs.

The median income of those using the program last year was $130,000 and the median purchase price was about $850,000, said Maria Benjamin, a director with the Mayor’s Office of Housing. Most of the homes were purchased in Districts 10 and 11, the city’s southeastern corner. When loans are repaid, that money goes back into the loan pool.

This year’s lottery results will be posted Aug. 31; after that the city will begin notifying winners. Once notified, buyers generally have 90 days to get into contract on a home. If they can’t, their money will be opened to the next person in line.

Adam and Lauren West entered the lottery last year and when their number was pulled early, they immediately started house hunting. By the time the city contacted them a few weeks later, they had already found a house in the Outer Sunset and had an offer accepted two days later. The couple used the $375,000 from the city, along with their own savings, to put down half the purchase price.

Lauren is a professional organizer and Adam works for a women’s health nonprofit. Without this help, there is no way the couple could have bought a home in San Francisco, where the median price is around $1.3 million.

“We wouldn’t be able to stay in the city if we didn’t buy a home,” Adam said. “We were in a single-family home in the Sunset, not rent-controlled. Eventually we would have been priced out.” Their mortgage payment “is not much more than we were paying in rent.”

When they sell the home, for which they paid just over $1 million, they’ll owe $375,000 plus about 35 percent of any appreciation. Adam feels OK about that now. “You are kind of paying it forward,” he said. “Maybe at the time I’ll feel not so happy about it.”

Of the funding, $2.2 million is reserved for San Francisco Unified School District educators and first responders, who can make up to 200 percent of median income.

The program charges a nonrefundable fee of $619 once a lottery winner has been notified and moves ahead.

Santa Clara County plans to launch a similar program for first-time buyers this fall. Housing Trust Silicon Valley will administer the new program. The trust, a nonprofit organization, is already offering a deferred loan down payment program for some buyers in Santa Clara County, Menlo Park and East Palo Alto.

Under a statewide program open year round, the California Housing Finance Agency offers deferred loans for down payments up to 3.5 percent of the purchase price, but the price can’t exceed $705,000. The income limits, though, are high — $228,300 regardless of family size in San Francisco. The MyHome Assistance loan must be paired with a first mortgage from the agency.

On the for-profit front, two San Francisco companies — Unison and Landed — have shared appreciation down-payment products funded by investors. Theirs have no income limits, but buyers still must get a mortgage from a participating lender. They take a bigger slice of the home’s appreciation than the San Francisco program, but will also share in any depreciation, which the city will not do.

Unison typically provides 10 percent of the purchase price; the buyer puts down 10 percent and borrows 80 percent. Unison’s investment comes due when the home is sold or refinanced or after 30 years. At that point the buyer pays Unison its original investment plus or minus 35 percent of the home’s appreciation or depreciation. If the home has lost value, the owner repays less than Unison’s original investment. The buyer can also buy out Unison after three years.

Alternatively, Unison will provide 15 percent of the purchase price in exchange for 52 percent of any appreciation or depreciation.

By comparison, if San Francisco provided 10 percent of the purchase price, it would take only 10 percent of any future appreciation, but it won’t take a hit if the home price drops.

Unison also charges a setup fee equal to 2.5 percent of the down payment it provides, or $2,500 on a $100,000 investment.

Landed has a similar program for teachers and other employees of participating public school districts. To “participate,” the district only has to announce the program to employees and let Landed give them a sales pitch, usually on campus after school hours.

Buyers must put down at least 10 percent. If Landed provides another 10 percent, it takes 25 percent of any appreciation or depreciation. Buyers pay no origination fee if they use a Landed partner real estate agent, who pays Landed a fee. If buyers use their own agent, that agent must pay Landed the same fee, which the company would not disclose.

Landed co-founder Jesse Vaughan said it has completed 90 transactions, most in the Bay Area.

Kathleen Pender is a San Francisco Chronicle columnist. Email: kpender@sfchronicle.com Twitter: @kathpender