TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #397 · 12 ное.

Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs

Резултати

Пронајдени 2 слични објави

Пребарај: #pnptc

当前筛选 #pnptc清除筛选
StartupBase

@startupbaseuz · Post #5834 · 17.06.2025 г., 06:19

📣 Open Call: Enterprise & AI Startups — Your Moment Is Now! 🚀 Plug and Play Central Asia, in partnership with IT Park Uzbekistan, is on the lookout for high-potential startups from Central Asia and around the globe to join Batch 5 of Plug and Play Tech Center Accelerator Program in Uzbekistan. Who should apply? ✔️ International startups ready to expand into Central Asia and establish a footprint in Uzbekistan ✔️ Homegrown Uzbekistan-based startups looking to scale fast with world-class support ✔️ High-growth startups with real traction and global ambition What’s in it for you? ✔️ Expert mentorship and hands-on support from Plug and Play's global network ✔️ Investment opportunities and warm intros to VCs ✔️ Exclusive access to pitch at our Expo in front of corporates and investors ✔️ Practical workshops and pitch training sessions ✔️ The chance to join Plug and Play Tech Center GOAL Program in Silicon Valley and visit other locations IT Park Ventures will review all participating startups for investment - supporting international startups considering entering Uzbekistan and helping local founders scale worldwide. Applications are open here:link 🗓 Deadline to apply: July 15, 2025 🟢 Selected startups will be announced in August. The program kicks off in early October. Apply now and let’s build the future together! #PNPTC#PlugAndPlayCA#Uzbekistan#Accelerator#Batch5#OpenCall#ITPark

IT Park Ventures

@ITParkVentures · Post #234 · 17.06.2025 г., 07:24

📣 Open Call: Enterprise & AI Startups — Your Moment Is Now! 🚀 Plug and Play Central Asia, in partnership with IT Park Uzbekistan, is on the lookout for high-potential startups from Central Asia and around the globe to join Batch 5 of Plug and Play Tech Center Accelerator Program in Uzbekistan. Who should apply? ✔️ International startups ready to expand into Central Asia and establish a footprint in Uzbekistan ✔️ Homegrown Uzbekistan-based startups looking to scale fast with world-class support ✔️ High-growth startups with real traction and global ambition What’s in it for you? ✔️ Expert mentorship and hands-on support from Plug and Play's global network ✔️ Investment opportunities and warm intros to VCs ✔️ Exclusive access to pitch at our Expo in front of corporates and investors ✔️ Practical workshops and pitch training sessions ✔️ The chance to join Plug and Play Tech Center GOAL Program in Silicon Valley and visit other locations IT Park Ventures will review all participating startups for investment - supporting international startups considering entering Uzbekistan and helping local founders scale worldwide. Applications are open here:link 🗓 Deadline to apply: July 15, 2025 🟢 Selected startups will be announced in August. The program kicks off in early October. Apply now and let’s build the future together! #PNPTC#PlugAndPlayCA#Uzbekistan#Accelerator#Batch5#OpenCall#ITPark