Skip to main content

A simple, flexible Python HTTP client and API modeling toolkit built on httpx and pydantic.

Project description

python-requests-client

A simple, flexible Python HTTP client and API modeling toolkit built on top of httpx and pydantic. Easily integrate robust API requests and resource models into your Python projects.


🚀 Features

  • Model-driven: Define and interact with API resources as Python classes.
  • Easy HTTP Requests: Simple RequestClient for GET, POST, PUT, DELETE with automatic header and base URL management.
  • Pydantic API Models: Define resource models with CRUD helpers (save, delete, load, find).
  • Global Client Setup: Set a global API client for all models with set_client().
  • Type Safety: All models use Pydantic for validation and serialization.
  • Extensible: Easily create new models for any RESTful resource.

📦 Installation

pip install python-requests-client

🔧 Usage

1. Define Your Models

from pyrest_model_client.base import BaseAPIModel
from typing import ClassVar


class User(BaseAPIModel):
  name: str
  email: str
  _resource_path: ClassVar[str] = "user"


class Environment(BaseAPIModel):
  name: str
  _resource_path: ClassVar[str] = "environment"

2. Initialize the Client

from pyrest_model_client import RequestClient, build_header, set_client
from example_usage.models.user import User
from example_usage.models.environment import Environment

set_client(
  new_client=RequestClient(
    base_url="http://localhost:8000",
    header=build_header(token="YOUR_API_TOKEN")
  )
)

# Create and save a new user
e = User(name="Alice", email="alice@example.com")
e.save()

# Update and save
e.name = "Alice Smith"
e.save()

# Find all environments
environments = Environment.find()
print(environments)

# Load a specific user by ID
user = User.load(resource_id="123")

# Delete a user
user.delete()

🤝 Contributing

Contributions are welcome! Please fork the repo, create a branch, and submit a pull request.


📄 License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrest_model_client-0.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrest_model_client-0.0.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pyrest_model_client-0.0.1.tar.gz.

File metadata

  • Download URL: pyrest_model_client-0.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyrest_model_client-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f552f46adda18ee357d09637f748ee479d0bd644467199c847dbb42bf7552591
MD5 6e425726a678393e5c3b4b0d7089c4da
BLAKE2b-256 32bebedef56b142ab78f355eea9c9f6402932365545deb8e32794d6b2a8ceed2

See more details on using hashes here.

File details

Details for the file pyrest_model_client-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyrest_model_client-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63ae4f3887217f2ddd8d260dc59e66765b43305376eb9250f78c3f12ed32e243
MD5 d8ee5e2bdc7ddb2b70ad2cdb166ddd71
BLAKE2b-256 e56cd3fe229c7cb118ab4eee7b51a31a2af4de39d6ae5abc6fd05ccf9d20c8af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page