Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sortedcontainers-pydantic

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sortedcontainers-pydantic

Pydantic support for the sortedcontainers package.

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

sortedcontainers-pydantic

PyPI Supported Python versions tests codecov

This package adds Pydantic support to sortedcontainers, a fast pure-Python library for sorted mutable collections.

It implements Pydantic's special methods on subclasses of sortedcontainer's SortedDict, SortedList, and SortedSet classes so that you can use them with Pydantic's models, validation, and serialization. To use, simply import the respective class of the same name from sortedcontainers_pydantic instead of from sortedcontainers. Only Pydantic V2 is supported.

from pydantic import BaseModel, TypeAdapter
from sortedcontainers_pydantic import SortedList

class MyModel(BaseModel):
    sorted_list: SortedList[int]

MyModel(sorted_list=[3, 1, 2])
#> MyModel(sorted_list=SortedList([1, 2, 3]))

MyModel.model_validate_json('{"sorted_list": [3, 1, 2]}')
#> MyModel(sorted_list=SortedList([1, 2, 3]))

MyModel(sorted_list=[3, 1, 2]).model_dump_json()
#> '{"sorted_list":[1,2,3]}'

TypeAdapter(SortedList).validate_python([3, 1, 2])
#> SortedList([1, 2, 3])

TypeAdapter(SortedList).validate_json("[3, 1, 2]")
#> SortedList([1, 2, 3])

Reproducible example created by reprexlite v0.5.0

Installation

sortedcontainers-pydantic is available on PyPI. You can install it with

pip install sortedcontainers-pydantic

Keywords

FAQs


Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc