Python API's | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python API's

I have created API's in CSharp before I would like to know how you can connect Python API's to a CSharp application if it is even posible

17th Jul 2020, 6:52 PM
Werner
1 Answer
+ 1
Connecting Python with c# is definitely possible but the big differences between .net and Python make it cumbersome to tightly couple the two together. Since your question was tagged with flask and web forms, your software probably already talks with a web server. Since you already have a web server and Python and c# compile and run in such different ways, I recommend wrapping both API's in HTTP. You can host the Python API's with a separate HTTP server from your .net-oriented server. In other words, if Python wants to use a c#-implemented API, just hit it over HTTP and vice versa. In the end, you'd have a Python-oriented web server using something like Flask or Tornado. You'd also have a .net-oriented web server using something like Microsoft IIS. Each server would make its API's available as HTTP targets. If you also had a web application, it would be up to you which server hosts that content. HTTP would add complexity with asynchronous calls and overhead around processing more HTTP requests but this separation is most-likely worth it. You could have Python code call a dll compiled from your c# code which will likely perform better than my main suggestion but with drawbacks that make it an uglier alternative.
18th Jul 2020, 4:10 PM
Josh Greig
Josh Greig - avatar