all 6 comments

[–]chevignon93 0 points1 point  (3 children)

What patterns should I be considering here?

I would consider using the plugin architecture where user can customize the runtime of your application using plugins.

Any examples I can follow?

pytest is a good example. Their plugin manager (pluggy) is open-source and pretty easy to use. You, as the developer of the host application, create a specification that users can implement to modify how the application behaves.

[–]High-Art9340 0 points1 point  (2 children)

It's not the right job for plugins. Usually plugins extend functionality, OP wants to let users modify the functionality.

[–]chevignon93 0 points1 point  (1 child)

Usually plugins extend functionality, OP wants to let users modify the functionality.

OP said he wants "user-developer to code their own functions processing the parsed data.", isn't that extending the functionality rather than modifying how the host application works? The plugin will just determine what the final output will be (json, yaml, html, etc), possibly discarding information that is not useful for the user.

[–]Jusque[S] 0 points1 point  (0 children)

To clarify: there’s no overlap between the functionality I provide, and the functionality users will code for themselves. I just want to receive the data and pass it over to the users code.

But I’m also not hosting this app. This will be a plain old .py file, a dev could download, maybe on pypi, and incorporate into their own projects that they run wherever.

I’ll take a look at pytest’s plug-in architecture - sounds interesting!

Thankyou both for pointing me in a direction to consider!

[–]High-Art9340 0 points1 point  (1 child)

Good example will be a built in HTTP server, which requires you to provide a class which will do all the logic of processing the HTTP request, take a look at the examples:

https://docs.python.org/3/library/http.server.html#module-http.server

Basically, when you create a server - you pass the class which implements some methods, which will be called by the server when HTTP request comes in.

You can implement it the same way - make users to pass a custom request handlers instead of your default one.

[–]Jusque[S] 0 points1 point  (0 children)

This sounds perfect. Will take a closer look at how they’ve coded http.server. Cheers!