Использование 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
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce Our #BinanceLive AMA with BOSS || 5th January 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 5th January , 2026 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Project Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉BOSS
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Clarnium on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
⏰ Must Join " BOSS Social Media Links :
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Stake Cash Coin(SACO) || 1st December, 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 1st December , 2025 at (2:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Project Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Stake Cash Coin(SACO)
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Stake Cash Coin(SACO) on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/live/video?roomId=2285385
⏰ Must Join " Stake Cash Coin(SACO)" Social Media Links :
❌Twitter
✉️Telegram
🌐Website
📷Instagram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with AIO protocol || 21th November , 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 21th November , 2025 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Chloe & Jade
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉AIO protocol
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝AIO protocol on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283711
⏰ Must Join " AIO protocol" Social Media Links :
❌Twitter
✉️Telegram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with GIGGLE FUND || 16th November , 2025 at ( 6:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 16th November , 2025 at (6:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest :
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉GIGGLE FUND
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝GIGGLE FUND on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
⏰ Must Join " GIGGLE FUND" Social Media Links :
❌Twitter
🔥Website
✉️Telegram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Usd1swap || 13th November , 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 13th November , 2025 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest :
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Usd1swap
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Usd1swap on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283379
⏰ Must Join " Usd1swap" Social Media Links :
❌Twitter
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with MetaPi || 10th November , 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 10th November , 2025 at (2:00PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Caitlyn
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉MetaPi
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝MetaPi on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283001
⏰ Must Join " MetaPi" Social Media Links :
❌Twitter
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with MetaPi || 14th October , 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠🔠🔠
🔠🔠
🔠🔠
⏳ Time : 14th October , 2025 at (2:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Caitlyn
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉MetaPi
✅Like & Retweet✅Twitter Post
✅ Follow
📝CryptoFight &
📝MetaPi on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/live/video?roomId=2280210
⏰ Must Join " MetaPi" Social Media Links :
❌Twitter🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram✉️Channel
📝Twitter🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Biokript-Bro || 09th October , 2025 at ( 3:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 09th October , 2025 at (3:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Adnan Alisic, CEO, Adnan_Biokript
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Biokript-Bro
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Biokript-Bro on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2280011
⏰ Must Join " Biokript-Bro" Social Media Links :
❌Twitter
✉️Telegram
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "CDL" at 11th February 2025 at ( 4:PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 11th February 2025 ( 4: PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 50$ USDT
🤵♂️Guest : CDL Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉CDL
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝CDL on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2249344
⏰ Must Join "CDL" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "EvolveToken" at 3th February 2025 at ( 2:PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 3th February 2025 ( 2:00 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Seth Founder Of Evolve
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉EvolveToken
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝EvolveToken on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2248252&utm_campaign=binance_live
⏰ Must Join "EvolveToken" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "StohnCoin" at 6th February 2025 at (3 PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 6th February 2025 ( 3:00 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Ing. Jozef Libant - CEO / Brett Weigel - COO / Jason Stanley - CIO / Alexander Almkvist - CTO
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝StohnCoin on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2248211
⏰ Must Join "StohnCoin" Social Media Links :
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "POPG" at 21th February 2025 at ( 12 PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 21th February 2025 ( 12 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Petra Apostolovic - PR & Community and Gabriel Raimundi - Marketing
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉POPG
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝POPG on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2247598
⏰ Must Join "POPG" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight