
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
numpy-pydantic-types
Advanced tools
numpy-pydantic-types is a Python library providing numpy scalar data types compatible with pydantic, allowing for easy validation and enforcement of numerical precision in pydantic models.
numpy-pydantic-types is a Python library providing numpy
scalar data types compatible with pydantic
, allowing for easy validation and enforcement of numerical precision in pydantic
models.
pydantic
models rely on Python's native types (e.g., int
, float
, str
) for data validation, which can be limiting when working with scientific or numerical applications that require specific numpy
types, like float32
, uint16
, or int8
. This library bridges that gap by introducing numpy scalar types as valid pydantic field types, allowing you to define precise, controlled models that integrate with scientific workflows.
pydantic
models using numpy
scalar types like float32
, uint32
, int8
, etc.numpy
types in your pydantic
models.pip install numpy_pydantic_types
This library enables the use of numpy
scalar types directly within pydantic
models. Here’s how to set up a model using numpy
types:
from pydantic import BaseModel, ValidationError
from numpy_pydantic_types import Float32, UInt32, UInt16
class ScientificModel(BaseModel):
precision_value: Float32 # Enforces a 32-bit floating point
sample_count: UInt32 # Enforces a 32-bit unsigned integer
sensor_id: UInt16 # Enforces a 16-bit unsigned integer
# Example data
data = {
"precision_value": 1.234567,
"sample_count": 4294967295, # Max value for UInt32
"sensor_id": 65535 # Max value for UInt16
}
# Instantiate the model with the specific numpy types
try:
model = ScientificModel(**data)
print("Model validated successfully:", model)
except ValidationError as e:
print("Validation error:", e)
The library provides a range of numpy
scalar types that can be used in pydantic
models, including:
Float32
, Float64
Int8
, Int16
, Int32
, Int64
UInt8
, UInt16
, UInt32
, UInt64
Using specific numpy
scalar types can help enforce type constraints in applications where precision or memory footprint is crucial, such as scientific computations, data analysis, or embedded systems.
from numpy_pydantic_types import Int8, Float64
class DataProcessingModel(BaseModel):
temperature: Float64
adjustment_factor: Int8
UInt8
ranges from 0 to 255).MIT License
FAQs
numpy-pydantic-types is a Python library providing numpy scalar data types compatible with pydantic, allowing for easy validation and enforcement of numerical precision in pydantic models.
We found that numpy-pydantic-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.