Использование 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
Lookonchain | ꘜ
A newly created wallet (0xa523) deposited 23.52M $USDC into #Hyperliquid to buy 466,421 $HYPE ($21.5M) and 2.16M $Fartcoin ($2.12M) in the past 7 hours.
https://hypurrscan.io/address/0xa5232e97b4ded3d2EF25Be059c3489e61Be475Aa
A newly created wallet deposited $3.18M $USDC into #HyperLiquid and opened an $ETH long position with 20x leverage.
The whale is likely to increase the position or open a new one.
@Runlifenick_fx✅
A mysterious whale wallet 0x579f has deposited $2.91M USDC into #Hyperliquid over the last 48 hours — taking massive leveraged bets across three major assets:
• Short 232 BTC (~$25M)
• Short 5,810 ETH (~$22.7M)
• Long 44.79M ENA (~$21.3M)
That’s a combined open position of nearly $70M, signaling a strong rotation from majors to ENA.
https://hypurrscan.io/address/0x579f4017263b88945d727a927bf1e3d061fee5ff
A whale recently created a new wallet (0xb0a0) and deposited $4 million USDC into #Hyperliquid, signaling a major move to accumulate $HYPE.
So far, the wallet has purchased 58,778 $HYPE worth approximately $2.89 million.
https://hypurrscan.io/address/0xb0a0f97898682E3c0A83633DF67E67249d6B12fa
As $UNI is trading at ~$10, a whale holding a $UNI long position with 10x leverage currently has a floating profit of $3M on #HyperLiquid.
The whale also has long positions on $ETH (25x), $BTC and $SOL with 20x leverage, with floating profit of $9.38M.
Overall, the whale is making $31.9M.
https://hyperbot.network/trader/0x9263c1bd29aa87a118242f3fbba4517037f8cc7a
A newly created wallet "0x01f" deposited 242 $ETH into #HyperLiquid to sell, then opened a 3,286.46 $ETH short position with 20x leverage valued at ~$7M.
https://hyperdash.com/address/0x01f135c734b4aae018ebf4e7995c560a38422e50
https://x.com/OnchainLens/status/2041019716492537964
Follow @onchainlens for more onchain updates
After 5 months, a whale deposited $1M $USDC into #HyperLiquid and opened a 20,000 $BRENTOIL long position with 20x leverage.
Previously, the whale has made over $12.44M.
https://hyperbot.network/trader/0x9aB1c356E6Af86361446497FCe954B3CDF940206
https://x.com/OnchainLens/status/2040359551682412700
Follow @onchainlens for more onchain updates
A wallet deposited $2.25M $USDC into #HyperLiquid and opened a 2,271.55 $GOLD ($10M) long position with 10x leverage. https://hyperbot.network/trader/0x06a33efba1ea066af486d3d8b89eea896ec1cf69 https://x.com/OnchainLens/status/2036242636579938809 Follow @OnchainLens…
Machi deposited another $300K USDC into #HyperLiquid to increase his $ETH (25x) long position.
Earlier, Machi partially closed the position at a loss to avoid liquidation.
Machi’s loss is now over $31.29M.
https://hyperbot.network/trader/0x020ca66c30bec2c4fe3861a94e4db4a498a35872
https://x.com/OnchainLens/status/2039617823027425483
Follow @onchainlens for more onchain updates
A newly created wallet deposited $9.6M $USDC into #HyperLiquid and opened a $CL long position with 20x leverage. The position is still increasing. https://hyperbot.network/trader/0x9D32884370875f2960D5CC4b95Be26687d69Aff5 https://x.com/OnchainLens/statu…