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.4.tar.gz (6.0 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.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyrest_model_client-0.0.4.tar.gz
Algorithm Hash digest
SHA256 cafb95d46c74a8f51781d4946296c2fa3a60731dd9e970855050efcb15b6bbda
MD5 cdb430842ea57e72e2eba13b3596f67a
BLAKE2b-256 86309ac45b0cc399be4b7fbcdbfcb82bdbdf9da90d42cfccf4a62b4bca1973ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrest_model_client-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7218debc165ca00eabea5cac21748016a420e9cfd583901d06da850036185b0c
MD5 54a43f4b8f3af0de7cf803d1db71c3ee
BLAKE2b-256 17c2a502e1255b031ff74f8b666d8ec076ee8944267ee2f210e743fec76575cb

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