The ruling came after Mexico United Against Crime (MUCD), an NGO filed legal papers to change the country’s drug policies.
This is the first time cocaine use is legalized in Mexico but the ruling has to be ratified by a higher court.
"We have been working for a safer, more just and peaceful Mexico for years, and with this case we insist on the need to stop criminalizing users of drugs other than marijuana and design better public policies that explore all available options, including the regulation," Lisa Sanchez, director of MUAC, said in a statement.
The judge said that they can intake cocaine only 500 milligrams per day when they are not working, driving, or operating heavy machinery. They cannot consume it in public or in the presence of children, neither can they encourage others to consume it.
Judge Víctor Octavio Luna Escobedo said that cocaine’s use for recreational purposes has many benefits, including "tension relief, the intensification of perceptions and the desire [to have] new personal and spiritual experiences."
Mexico's national health regulator the Federal Commission for the Protection against Sanitary Risk is seeking to block the order.
Mexican President Andres Manuel Lopez Obrador promised a radical change to end the war on drugs. He argued for decriminalizing all drugs to take away power from drug cartels.