vaphes / pocketbase

PocketBase client SDK for python
https://pypi.org/project/pocketbase/
MIT License
332 stars 38 forks source link

add json serialization support for various types #27

Closed dsikes closed 1 year ago

dsikes commented 1 year ago

Great work on this SDK.

This is a request for an enhancement to support JSON serialization for the different types supported

Eg:

import json
from pocketbase import PocketBase 

client = PocketBase('http://127.0.0.1:8090')

# authenticate as regular user
user_data = client.collection("users").auth_with_password("foo@bar.com", "thisIsAFaksePassword123")

# get a compliance report
report = client.collection("compliance").get_list()

print(json.dumps(report, indent=4))

This currently results in:

Traceback (most recent call last):
  File "/Users/dansikes/go/src/github.com/dsikes/equip/scripts/test.py", line 12, in <module>
    print(json.dumps(report, indent=4))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ListResult is not JSON serializable

Happy to work on a PR, but wanted to see if this was something you'd consider before doing so.

Thanks!

vaphes commented 1 year ago

@dslikes I think it would be really nice to have it! Please fell free to submit a PR and I will get it verified asap.

Thanks!

ronnyandre commented 1 year ago

Would absolutely love to have this feature!!