(Migrated) how to add custom python libraries that are used by a service

(This message has been automatically imported from the retired mailing list)

I have a written a small python class (converter) to convert xml into
another xml using xslt. Now I want to create a service that leverages this
python class(reads a file, convert the content into xml, use this library
to convert xml and then write the output to another file) . How do I bundle
my custom python class (converter) along with the service. Do I put both my
service code and custom code in server pickup dir do I need to wrap this
custom code into a zato service and then invoke it somehow?

Navjeet

You can place your code in a folder called zato_extra_paths that is inside
your Zato installation folder. All the libraries you need to use in a
service you should place it there to allow Zato to use it
Cheers

On Sat, Jan 11, 2014 at 1:08 AM, Navjeet navjeetc@gmail.com wrote:

I have a written a small python class (converter) to convert xml into
another xml using xslt. Now I want to create a service that leverages this
python class(reads a file, convert the content into xml, use this library
to convert xml and then write the output to another file) . How do I bundle
my custom python class (converter) along with the service. Do I put both my
service code and custom code in server pickup dir do I need to wrap this
custom code into a zato service and then invoke it somehow?

Navjeet

On 01/11/2014 04:15 PM, Axel Mendoza Pupo wrote:

You can place your code in a folder called zato_extra_paths that is inside
your Zato installation folder. All the libraries you need to use in a
service you should place it there to allow Zato to use it
Cheers

Thanks Axel!

https://zato.io/docs/admin/guide/installing-services.html#zato-extra-paths

In addition to the above, if hot-deployment is needed, you can also wrap
your library code in a service, such as below.

https://zato.io/docs/progguide/service-dev.html#invoke

Note that in the code here you always invoke the LibaryService by its
name and depending on whether it’s defined in the same Python module you
can take a shortcut by using the .get_name() method or you need to
provide its full name yourself if both services are deployed in separate
modules.

In either case, you don’t import the classes services are defined as
between Python modules because that would possibly ruin the whole
concept of hot-deployment.

from zato.server.service import Service

class LibraryService(Service):
def convert(self, *args):
# place your code here
pass

def handle(self):
    return self.convert(self.request.input)

class UserExposedService(Service):
def handle(self):
# return self.invoke(LibraryService.get_name(), self.request.input)
# return self.invoke(‘my-lib-service’, self.request.input)
pass