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

Резултати

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

Пребарај: #sveltekit

当前筛选 #sveltekit清除筛选
GitHub Trends

@githubtrending · Post #15079 · 20.08.2025 г., 12:30

#typescript#svelte#sveltekit#tailwindcss#tauri Epicenter is a free, open-source set of local-first apps that let you own and control your data by storing everything—notes, transcripts, chats—in one simple folder using plain text and SQLite. You can use any AI model you want, customize tools, and access your data anywhere without relying on cloud services. Key apps include Whispering, which transcribes your speech locally, and epicenter.sh, a personal assistant that helps you search and interact with your data. This setup gives you privacy, flexibility, and full control over your information, avoiding locked, siloed apps and data traps. It’s great for anyone who values data ownership and open software. https://github.com/epicenter-so/epicenter

折腾实验室频道

@TossLabChannel · Post #424 · 22.12.2024 г., 03:30

#局域网唤醒#SvelteKit#Go#PocketBase 简单局域网唤醒 Web 应用程序 该应用程序利用 SvelteKit、Go 和 PocketBase 构建,适合家庭或企业环境中需要设备唤醒和管理的用户。 ✨ 特点 • 🚀 一键设备唤醒仪表板 • ⏰ 定时事件自动化(通过 Cron 设置) • 🔌 支持 Ping 任意端口 • 🔍 网络扫描发现设备(需要 nmap) • 👤 安全的用户管理 • 🌐 多语言支持(i18n) • 🎨 提供 29 种主题 • 🐳 支持多平台 Docker 镜像 • 🏠 完全自托管 📢 群聊: @TossLab 🎈 频道: @TossLabChannel ❤️不想错过精彩内容,请打开 #频道通知,你的 #阅读#点赞#转发 便是我发帖的最大动力!

GitHub Trends

@githubtrending · Post #15236 · 19.10.2025 г., 12:30

#typescript#chatgpt#hacktoberfest#huggingface#llm#svelte#svelte_kit#sveltekit#tailwindcss#typescript Chat UI is an open-source chat interface built with SvelteKit that lets you easily connect to different AI language models using any service that works with the OpenAI API format, such as Hugging Face, llama.cpp, Ollama, or OpenRouter[5]. You can quickly set it up on your computer by cloning the project, setting a few environment variables (like your API key and database connection), and running simple commands to start the app—no need to be an expert[5]. The main benefit is that you get a modern, customizable chat app that works with many AI models, making it simple to experiment, build, and share your own AI-powered chat experiences without starting from scratch. https://github.com/huggingface/chat-ui