How to use a async library in Django view? - python

I need to use a Python library that handles requests through the API of a web service. This library is an asyncio supported library. So I can't use it in a Django view by following the traditional and appropriate ways..
So what should I do to overcome this issue? I just thought that I can create a .py script and it would handle this library and I would use it in my Django view with os.system('...py') but it just looks awful.
Could you help me to find a way that looks just "normal"?

Related

How to use python and wix for web development [duplicate]

I'm trying to integrate backend code into a Wix site. Im not too picky about how I want to do this, or what language to write in (ideally, I have a locally-hosted Java code that I'd love to simply call). I wouldn't mind re-writing it in JavaScript though, or another language. But before I decide that I'm confused about my options. I can code but I'm new to the concepts like modules, APIs, & servers.
According to my research, back-end code with Wix is supposed to be easy (or at least do-able and not THAT complicated)....
From this webpage https://support.wix.com/en/article/corvid-calling-server-side-code-from-the-front-end-with-web-modules,
"Web modules are exclusive to Corvid and enable you to write functions that run server-side in the backend, and easily call them in your client-side code. With web modules you can import functions from backend into files or scripts in public, knowing they will run server-side. Corvid handles all the client-server communication required to enable this access."
And from this: https://www.sitepoint.com/what-is-wix-code/
"It’s serverless: All this added functionality comes in a serverless environment that lets you get your work done without any of the normal full-stack development headaches.
Just code and go: Wix Code has a built-in, online IDE and backend so you can just add the code you need to your page or your site, publish, and you’re live."
So, I thought they have a backend IDE where I can write backend code directly, or I could call my Java program. But, as I tried doing this and finding tutorials, it seems I can really only do this by calling a public API from the backend...?
https://youtu.be/tuu0D1izrUU
But ive also read (and someone who supposedly has done it before told me this) that Wix integrates with node.js, which is a backend version of JavaScript.
Can I use a Wix domain for a NodeJS app?
But, when I go into my Wix site I cannot find any option for using Node JS, and doing research on that gives me no useful results.
So, I'm thoroughly confused on what the capabilities are here. Can someone help me make sense of this?
Why are there no tutorials showing explicit code in the Corvid backend module? What's stopping me from simply writing my Java program there in a module? Do I really need an API endpoint to call and pass to the front end?
Is Node JS supported or not - has anyone done this before?
Also, in one link above they said everything is "serverless". But if I have to set up my own API endpoint won't I need to set up my own server??
There are basically two ways to go about this, which you seem to have already discovered.
Write your backend code in your Wix site. Indeed, the backend is built on Node.js as you can see here. Using this approach you will have to use JavaScript. As you seem to have found, you write this code in the Backend section of your site in a Web Module. Pros: you don't need to worry about managing a server and all your code is in one place.
Expose your already existing Java code as an API that your Wix site can call using the wix-fetch API. Pros: you don't need to rewrite your code.

How can I Integrate Python Scripts into a MERN stack

I am thinking of adding python scripts for some data analysis but I am using a MERN stack for my application.
An example of what I am thinking-
My python script will do some data analysis when an endpoint is being called.
../api/dopythonhere and return a JSON object
What would be the best/efficient way to implement python with a MERN stack?
So as far as I understood you have currently an API or full-build functional application made in or partially coded in Python (unknown stack). Therefore you want to migrate this to MERN Stack or call the Python API via your MERN application. There are several things you can do to work with this, but those two might be the cleanest:
Completely migrate and integrate your Python app into your Node.js & Express app and forget about the Python source code.
If it's not already done, make the Python app a functional web API. Therefore you can call it either from the Node API using libraries like Axios or similar (so in your API you can modify the data structure and only send to the front what you need), or you can also call the Python API directly via React front-end, using web development vanilla APIs or any libraries you want.

How to integrate or use docusign(api) using django?

I have done one small app using Django. Now, i'm trying to integrate docusign to my app.I have undergone through this url : https://github.com/peopledoc/django-docusign/tree/master/demo but it's not working .Any suggestions please?
Since Django is open source and it's based on python, you could build it yourself, add our Python SDK and make the API calls this way. Our Python SDK is also open sourced here - https://github.com/docusign/docusign-python-client

Python in browser with NLTK or alternative?

Is there a Python front-end that supports nltk?
I am building a custom application that needs to do stemming and stopping, and related processing, on a simple words query from inside the browser. I am familiar with nltk's stem/stop functionality, but a quick google of Python front-end alternatives listed in this thread does not turn up support for nltk. I tried pypy.js from its website, entered "import nltk," and it failed.
(I plan to use CherryPy as the back-end, if it matters, to serve up the application to the browser on first contact, and process the outputs.)
Is there a front-end that works with nltk? Alternatively:
Can I add nltk support to any of these environments, and how?
Is there another library that does stemming/stopping that works with these front-ends?
Thank you!
You're probably best off using a JavaScript NLP library of which there are several, like NLPJS, although I can't judge its quality.
If you use Transcrypt in your browser you can use objects and call functions from that library without conversion.
So you can program in Python, while your library is in JS.
you can use flask to show your python in web browser. Flask is a web framework. This means flask provides you with tools, libraries and technologies that allow you to build a web application.
In your case you can use flask to get data from browser and analyse your data and then show the result in browser.
you can see a word cloud example with flask here.

Making GUI with only python without framework?

Is it possible to create a user interface without the help of python framework (like tinker or pygame) and use only vanilla python code? If yes, how?
Can you briefly explain how python framework works?
Is the code of different python framework different?
If the computer did not have the framework installed, will the program still runnable if the program uses a framework?
Thanks very much
Yes, after all tinker and pygame are just python classes packaged as modules.
Python frameworks are a bunch of pre-tested and reusable modules that allow you to use and extend upon so you don't have to reinvent the wheel.
Yes, frameworks will have differences in usability and code.
The computer will always need the dependencies, though you can package these in various ways aka create a package that has all your dependencies for the program to run.
If you want as few external dependencies as possible (but still a GUI) I would strongly suggest using a Web-Microframework like bottle (single file) and utilize the user's browser for rendering.
You can make a GUI without any external framework with HTML by setting up a webserver and using the user's browser to render it.
For a browser-GUI without an external Framework: Depending on whether you know JavaScript you can either use XML-RPC (xmlrpc.server+http.server with JS in the browser) or WSGI (wsgiref) (example on that page)
Yes, totally.
Of course the if you do not prepare for this case you cannot run a program without an integral part of it like a Framework - but you can distribute your program with the Framework included.
For XML-RPC
import xmlrpc.server
import http.server
class MyHandler(xmlrpc.server.SimpleXMLRPCRequestHandler,http.server.SimpleHTTPRequestHandler):
pass
This handler will serve files from the current working directory (your actual HTML-UI and JS for communication (there are several XMP-RPC libraries for JS)) but it can also be used like in the XML-RPC-Server example to glue your code and the UI together.

Categories