π Kubernetes Cheat Sheet π
The 31 Commands You Need To Know π
#DevOps #DevOpsCommunity #Kubernetes #K8S
USEFUL CHANNELS FOR YOU
The 31 Commands You Need To Know π
#DevOps #DevOpsCommunity #Kubernetes #K8S
USEFUL CHANNELS FOR YOU
π7β€2
Forwarded from Learn Python Coding
Data validation with Pydantic! πβ¨
In the early stages of development, data validation usually doesn't cause problems. In many Python projects, validation initially looks simple:
But then come email, JSON from APIs, query parameters, nested objects, configs, nullable fields, and type conversion. At some point, the code turns into a set of if/else and manual checks.
For such tasks, Pydantic is often used. Installation:
Create a model:
Now the data is validated automatically:
The result:
30
<class 'int'>
Pydantic will automatically convert the string "30" to an int. If you pass an incorrect value, you'll get a ValidationError:
This is especially convenient when working with APIs, JSON, query parameters, and incoming data from outside.
A common production case is checking email:
If the email is invalid, Pydantic will throw a ValidationError. You can set default values:
And allow None:
This field becomes optional. A practical example is processing an API response:
The types will be automatically converted. For nested model structures, you can combine:
The nested object will also be validated. Serialization in Pydantic v2:
Pydantic is actively used in FastAPI, ETL, microservices, data pipelines, and API clients.
For working with environment variables in Pydantic v2, a separate package is usually used:
It's important to understand: Pydantic is not an ORM and does not replace business logic. Its task is to validate data, convert types, and describe schemas.
π₯ Pydantic significantly reduces the amount of manual data validation and makes processing incoming structures more predictable.
#Python #Pydantic #DataValidation #FastAPI #Coding #DevOps
β¨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
βοΈ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
In the early stages of development, data validation usually doesn't cause problems. In many Python projects, validation initially looks simple:
if not isinstance(age, int):
raise ValueError("age must be an int")
But then come email, JSON from APIs, query parameters, nested objects, configs, nullable fields, and type conversion. At some point, the code turns into a set of if/else and manual checks.
For such tasks, Pydantic is often used. Installation:
pip install pydantic
pip install "pydantic[email]"
Create a model:
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
Now the data is validated automatically:
user = User(
name="Alex",
age="30"
)
print(user.age)
print(type(user.age))
The result:
30
<class 'int'>
Pydantic will automatically convert the string "30" to an int. If you pass an incorrect value, you'll get a ValidationError:
User(
name="Alex",
age="test"
)
This is especially convenient when working with APIs, JSON, query parameters, and incoming data from outside.
A common production case is checking email:
from pydantic import BaseModel, EmailStr
class User(BaseModel):
email: EmailStr
User(email="[email protected]")
If the email is invalid, Pydantic will throw a ValidationError. You can set default values:
from pydantic import BaseModel
class Config(BaseModel):
host: str = "localhost"
port: int = 5432
And allow None:
from pydantic import BaseModel
class User(BaseModel):
nickname: str | None = None
This field becomes optional. A practical example is processing an API response:
from pydantic import BaseModel
class Product(BaseModel):
id: int
title: str
price: float
data = {
"id": "1",
"title": "Keyboard",
"price": "99.5"
}
product = Product(**data)
print(product)
The types will be automatically converted. For nested model structures, you can combine:
from pydantic import BaseModel
class Address(BaseModel):
city: str
zip_code: str
class User(BaseModel):
name: str
address: Address
user = User(
name="Alex",
address={
"city": "Berlin",
"zip_code": "10115"
}
)
print(user)
The nested object will also be validated. Serialization in Pydantic v2:
print(user.model_dump())
print(user.model_dump_json())
Pydantic is actively used in FastAPI, ETL, microservices, data pipelines, and API clients.
For working with environment variables in Pydantic v2, a separate package is usually used:
pip install pydantic-settings
It's important to understand: Pydantic is not an ORM and does not replace business logic. Its task is to validate data, convert types, and describe schemas.
π₯ Pydantic significantly reduces the amount of manual data validation and makes processing incoming structures more predictable.
#Python #Pydantic #DataValidation #FastAPI #Coding #DevOps
β¨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
βοΈ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Telegram
AI PYTHON π
Youβve been invited to add the folder βAI PYTHON πβ, which includes 15 chats.
β€6
Exporting the model from PyTorch to the universal ONNX format for independent inference π
Deploying PyTorch models in production often requires installing a large framework and relying on a Python environment. The ONNX (Open Neural Network Exchange) format converts the computation graph into an intermediate binary format suitable for running on any device and programming language. We will export the PyTorch neural network and run its inference using the lightweight ONNX Runtime. π
To export and run the neural network, we will install the PyTorch framework, the ONNX library, and the cross-platform ONNX Runtime engine.
The packages for converting and high-performance execution of graphs have been successfully installed. β
We will write a Python script that creates a test PyTorch model, exports it to a
The model graph has been successfully serialized into a binary file, and the runtime performed the prediction without involving PyTorch. π¦
# verification (checks the correctness and structure of the saved ONNX model)
Expected output: ONNX Model Status: Valid
# cleanup (deletes the generated model file and cleans up binaries)
Converting neural networks to ONNX allows you to decouple inference from Python and run models in C++, Rust, Go, or directly in a web browser. Be sure to specify the names of the input and output tensors when exporting to simplify integration with the service. π»
#PyTorch #ONNX #MachineLearning #DeepLearning #AI #DevOps
β¨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
βοΈ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Deploying PyTorch models in production often requires installing a large framework and relying on a Python environment. The ONNX (Open Neural Network Exchange) format converts the computation graph into an intermediate binary format suitable for running on any device and programming language. We will export the PyTorch neural network and run its inference using the lightweight ONNX Runtime. π
To export and run the neural network, we will install the PyTorch framework, the ONNX library, and the cross-platform ONNX Runtime engine.
pip install torch onnx onnxruntime
The packages for converting and high-performance execution of graphs have been successfully installed. β
We will write a Python script that creates a test PyTorch model, exports it to a
.onnx file, and immediately performs a verification of the output.import torch, torch.nn as nn, onnxruntime as ort, numpy as np
model = nn.Sequential(nn.Linear(10, 5), nn.ReLU())
x = torch.randn(1, 10)
torch.onnx.export(model, x, "model.onnx", input_names=["input"], output_names=["output"])
session = ort.InferenceSession("model.onnx")
res = session.run(None, {"input": x.numpy()})
print("ONNX Output shape:", res[0].shape)
The model graph has been successfully serialized into a binary file, and the runtime performed the prediction without involving PyTorch. π¦
# verification (checks the correctness and structure of the saved ONNX model)
python3 -c "import onnx; model = onnx.load('model.onnx'); onnx.checker.check_model(model); print('ONNX Model Status: Valid')"Expected output: ONNX Model Status: Valid
# cleanup (deletes the generated model file and cleans up binaries)
rm -f model.onnx
Converting neural networks to ONNX allows you to decouple inference from Python and run models in C++, Rust, Go, or directly in a web browser. Be sure to specify the names of the input and output tensors when exporting to simplify integration with the service. π»
#PyTorch #ONNX #MachineLearning #DeepLearning #AI #DevOps
β¨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
βοΈ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Telegram
AI PYTHON π
Youβve been invited to add the folder βAI PYTHON πβ, which includes 15 chats.
β€1
π₯ Free IT & Dev Study Kits β 2026 Prep, No Signup
If youβre prepping for cloud, dev, or AI roles this year, these free kits cover the gaps most people skip β cert basics, hands-on labs, and mock exams. No signup traps, no hidden fees.
π Cert E-Book β covers Cisco & AWS fundamentals, good for first-time cert takers
β https://bit.ly/4yrk1Ti
πͺ Online Free Course β structured path, works as a refresher before exams
β https://bit.ly/4hUprRP
βοΈ Free AI Materials β LLM basics to fine-tuning practice notebooks
β https://bit.ly/4yt1iXy
π Cloud Study Guide β cheat-sheet style, handy for interview prep
β https://bit.ly/4el4Eod
π§ Free Mock Exam β test yourself before booking the real thing
β https://bit.ly/4sbWlkl
π Save this or forward it to your dev/study group β good resources are worth sharing. πͺ
π Community: https://chat.whatsapp.com/CS7VOvQCLZG5BJPazBGm1v
π² Personalized help: https://wa.link/xd2fu6
#Python #Cloud #AWS #Cisco #AI #MachineLearning #DevOps #ITCertification #FreeResources #TechCareers
If youβre prepping for cloud, dev, or AI roles this year, these free kits cover the gaps most people skip β cert basics, hands-on labs, and mock exams. No signup traps, no hidden fees.
π Cert E-Book β covers Cisco & AWS fundamentals, good for first-time cert takers
β https://bit.ly/4yrk1Ti
πͺ Online Free Course β structured path, works as a refresher before exams
β https://bit.ly/4hUprRP
βοΈ Free AI Materials β LLM basics to fine-tuning practice notebooks
β https://bit.ly/4yt1iXy
π Cloud Study Guide β cheat-sheet style, handy for interview prep
β https://bit.ly/4el4Eod
π§ Free Mock Exam β test yourself before booking the real thing
β https://bit.ly/4sbWlkl
π Save this or forward it to your dev/study group β good resources are worth sharing. πͺ
π Community: https://chat.whatsapp.com/CS7VOvQCLZG5BJPazBGm1v
π² Personalized help: https://wa.link/xd2fu6
#Python #Cloud #AWS #Cisco #AI #MachineLearning #DevOps #ITCertification #FreeResources #TechCareers
β€2