Why do I need to add toJson() to get fetchResult in python

Here is an example. I do my development in jupyter notebook

fr = c3.ServicePoint.fetch().toJson()
for obj in fr["objs"]:
  pass

In order for this code to work in the server, I need to remove .toJson()

fr = c3.ServicePoint.fetch()
for obj in fr["objs"]:
  pass

This is annoying because my python functions (nested with many fetch calls) work fine in python, but a direct copy paste of them would fail in server. I have to do a global remove of “.toJson()”

This is even more annoying when I want to debug some python code from the server. After copy-pasting to jupyter notebook, I have to add .toJson() to every fetch call manually.

Can’t we hide/automate this in c3remote?

This difference between Jupyter notebook development and server development is because of the difference in the Python runtimes used in each of these environments.

In Jupyter notebook development, with either your c3Remote connector or containerized Jupyter notebook connection to C3, the connector is “remote-types”, which means that your connection to the Type system is Type-aware. This means that your fetch result is a C3 object, which is a Python object with access to all the member functions and fields in the C3 Type, including the toJson() function.

In the server development, the default C3 connector is “remote”, which means your connection to the Type system is not Type-aware, so your fetch result is not a c3 Object object, just a Python dictionary.

If you want your server connector to match the Jupyter notebook connection to the C3 Type system, you will need to specify in your Python runtime definition that your connector is “remote-types”, and reprovision to your environment. Below is an example runtime definition with "connector": "remote-types" specified.

{
  "language": "Python",
  "runtimeVersion": <YOUR PYTHON VERSION>,
  "modules": {
    <YOUR CONDA LIBRARIES>
  },
  "repositories": [
    <YOUR REPOSITORIES>
  ],
  "connector": "remote-types",
  "runtime": "CPython",
  "id": "py-exampleRuntime",
  "name": "py-exampleRuntime"
}
2 Likes