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.2.tar.gz (5.9 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.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyrest_model_client-0.0.2.tar.gz
  • Upload date:
  • Size: 5.9 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.2.tar.gz
Algorithm Hash digest
SHA256 8d25558a3af5798aa25c15c517ea965378571b74cffbb1c5bfbd47050f2298bc
MD5 66bc37ca159c00b6858526904c03c6e0
BLAKE2b-256 5efc2aab63fa199dbc3468bc9040c2ec2e4465a49c8e4906345ef9ea3c49a950

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrest_model_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ecf048c8cc8f63d8b04cc5caf866b16a20d7ccd473ee8007d82be7d8d47c7fa0
MD5 7e74e7f05d0042f34f59b68d2c765af9
BLAKE2b-256 0db8c97f147c423a7b13fc5400a53d23bba5484e52cde109e1d8296275dc57e3

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