Metadata-Version: 2.4
Name: eazyrest
Version: 0.9.0
Summary: Building blocks for easy REST API consumption
Author-email: Geoffrey Mainland <mainland@apeiron.net>
License: MIT License
        
        Copyright (c) 2023-2026 Geoffrey Mainland
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: rest,http,api,json
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: certifi
Requires-Dist: dateparser
Requires-Dist: isodate
Requires-Dist: python-dateutil
Requires-Dist: pytimeparse2
Requires-Dist: requests[socks]
Requires-Dist: tzlocal
Provides-Extra: dev
Requires-Dist: types-dateparser; extra == "dev"
Requires-Dist: types-python-dateutil; extra == "dev"
Requires-Dist: types-requests; extra == "dev"
Requires-Dist: types-urllib3; extra == "dev"
Dynamic: license-file

# eazyrest

`eazyrest` is a small library for consuming REST APIs with less boilerplate. It combines a session-based API client with a lightweight, type-directed JSON object mapping layer that models REST resources as typed Python classes.

## Installation

```bash
pip install eazyrest
```

Requires Python 3.10+.

## Example

The example uses the public REST demo API available at [https://jsonplaceholder.typicode.com/](https://jsonplaceholder.typicode.com/).

```python
from eazyrest import API, JSONObject, json_object

demo_api = API("https://jsonplaceholder.typicode.com/")

class JSONPlaceholderObject(JSONObject):
  """A JSON object from the JSONPlaceholder API"""
  pass

# Set class variable to point to JSONPlaceholder API instance
JSONPlaceholderObject.api = demo_api

@json_object
class User(JSONPlaceholderObject):
  """Represents one user object from JSONPlaceholder API."""
  class_url = "/users/"

  id: int
  name: str
  username: str
  email: str
  address: dict
  phone: str
  website: str
  company: dict

  def __str__(self):
      return self.name

@json_object(field_map={'user': 'userId'})
class Todo(JSONPlaceholderObject):
  """Represents one Todo object from JSONPlaceholder API."""
  class_url = "/todos/"

  id: int
  user: User
  title: str
  completed: bool

# Load one object by primary key (GET /todos/1/)
todo = Todo(id=1)
print(todo.title, todo.completed)

# Demonstrate loading of related object
print(todo.user)

# Query a collection (GET /todos/?userId=1)
todos_for_user_1 = Todo.filter(userId=1)
print(len(todos_for_user_1))

# Access typed fields
first = todos_for_user_1[0]
print(first.id, first.user.id, first.user, first.title)
```

## License

MIT. See `LICENSE`.

## Development

```bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -U build twine
python -m build
python -m twine check dist/*
```

### Publishing

To publish to PyPI:

```bash
python -m twine upload dist/*
```

To publish to Test PyPI:

```bash
python -m twine upload --repository testpypi dist/*
```
