Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Http client base pydantic, with requests, aiohttp and httpx. Only support the json response.
only support
requests
:pip install pydantic-client
support
aiohttp
andrequests
:pip install "pydantic-client[aiohttp]"
support
httpx(async)
andrequests
:pip install "pydantic-client[httpx]"
support all:
pip install "pydantic-client[all]"
from pydantic import BaseModel
from pydantic_client import delete, get, post, put, pydantic_client_manager
from pydantic_client import ClientConfig
class Book(BaseModel):
name: str
age: int
@pydantic_client_manager.register(
ClientConfig(
base_url="https://example.com",
headers={"Authorization": "Bearer abcdefg"},
timeout=10
)
)
class WebClient:
@get("/books/{book_id}?query={query}")
def get_book(self, book_id: int, query: str) -> Book:
...
@post("/books", form_body=True)
def create_book_form(self, book: Book) -> Book:
""" will post the form with book"""
...
@put("/books/{book_id}")
def change_book(self, book_id: int, book: Book) -> Book:
"""will put the json body"""
...
@delete("/books/{book_id}")
def change_book(self, book_id: int, request_headers: dict = None) -> Book:
...
client = pydantic_client_manager.get()
# will get the book with book_id=1
book: Book = client.get_book(1)
# request_headers will overwrite the headers in client_config
client.change_book(1, request_headers={"Authorization": "Bearer abcdefg"})
And see the examples.
client_config
import aiohttp
from pydantic_client import ClientConfig, ClientType
client_config = ClientConfig(
client_type=ClientType.aiohttp,
base_url="https://example.com",
headers={"Authorization": "Bearer abcdefg"},
timeout=10,
session=lambda: aiohttp.ClientSession()
)
from pydantic_client.schema.file import File
from pydantic_client import post
@post("/download")
def download_file(self) -> File:
# you will get the bytes content of the file
...
FAQs
Http client base pydantic, with requests or aiohttp
We found that pydantic-client 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.