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 слични објави

Пребарај: #consumerai

当前筛选 #consumerai清除筛选
Venture Village Wall 🦄

@venturevillagewall · Post #3666 · 21.12.2024 г., 11:00

Funding Rounds Update: December 2024 Recent funding announcements highlight significant investments across various industries: - ATC Managers, LLC: $14M on Dec 19, 2024 - Nationwide private lender. - Boon: $15.5M on Dec 20, 2024 - AI solutions provider. - Accelergen Energy: $20M on Dec 19, 2024 - Clean power asset management. - Backflip AI: $30M on Dec 19, 2024 - AI content creation. - Justt: $30M on Dec 19, 2024 - Chargeback automation. - Decart: $32M on Dec 19, 2024 - Consumer AI platform. - Instant Transport Solution: $35M on Dec 20, 2024 - Transportation technology. - TBC Bank Uzbekistan: $37M on Dec 20, 2024 - Banking services. - RiverWoods Exeter: $39.68M on Dec 18, 2024 - Retirement community. - EPTME: $44M on Dec 16, 2024 - Lifestyle management. - JET Charge: $44.93M on Dec 19, 2024 - EV charging solutions. - Pasadena Private Lending: $50M on Dec 19, 2024 - Non-bank lending. - Earli: $60M on Dec 19, 2024 - Cancer early detection. - ALLO: $100M on Dec 19, 2024 - Real-world asset trading. - DP World Group: $100M on Dec 19, 2024 - Logistics management. - InoBat: $103.62M on Dec 20, 2024 - Sustainable battery production. - ŌURA: $200M on Nov 19, 2024 - Health monitoring technology. - Metsä Group: $208.40M on Dec 19, 2024 - Renewable products. - Collectivus Holdings: $250M on Dec 19, 2024 - Investment management. - Nigerian National Petroleum Corporation (NNPC): $1B on Dec 17, 2024 - Petroleum services. #Funding#Investment#AI#Lending#Logistics#CleanEnergy#HealthTech#Batteries#ConsumerAI#EV#Retirement#Finance#Cancer#Sustainability#Transport#Renewables#RealEstate#Tech#NonBank#Petroleum#Automation

Venture Village Wall 🦄

@venturevillagewall · Post #3649 · 21.12.2024 г., 10:24

Decart Secures $32M Funding Round Decart raises $32M in a funding round on December 19, 2024. The company aims to democratize consumer AI with innovative solutions. Backed by Sequoia Capital and Zeev Ventures, Decart enhances GPU efficiency for AI model training, making advanced AI tools more accessible. It disrupts gaming and entertainment by enabling immersive experience creation from text prompts. Learn more #Decart#Funding#AI#GPU#Gaming#Entertainment#SequoiaCapital#ZeevVentures#ConsumerAI#TextToExperience#Innovation#Platform #2024 #Revolutionary#Technology#Access#Development#Efficiency#Democratization#Tools#Industry