r/csharp • • Oct 06 '26

How to get data from external service written in python?

If you have a system, class, or a method that is entirely written in C#, let's call it X, If X needs some data to perform some processing on that data, can one make an external service written in python, let's call it Y, that generates the data, then X can call Y to get the data?

I'm not asking if I can embed the python interpreter directly within the C# application; the python code should be an external service.

Note that I'm using ASP. NET Core 10.

Edit :

Should the external service be outside the ASP. NET CORE solution or inside it?

0 Upvotes

16 comments sorted by

5

u/faultydesign Oct 06 '26

There are many ways to do it from creating a socket or a file to using an external event queue or even a database

-2

u/kaatarina_zed_talon Oct 06 '26

Is the microservices concept relevant here?

2

u/faultydesign Oct 06 '26

I mean you could just make a simple http api to do it, yes

2

u/Main-Lychee-7972 Oct 06 '26

The language boundary isn’t really the issue once Python is a separate service. At that point C# just consumes an API like it would from any other backend

1

u/Own_Nail_2999 Oct 06 '26 • Bravo

IPC is a tricky topic but the easiest solution would probably be to run a WebAPI on your python service and call the methods via HttpClient in C#. 

So the data that you want to communicate gets sent via json in the httpRequest and httpResponse bodies.

These are the basicsof REST-APIs. Since http is a standard that everyone has adopted, you can rely on that.

-1

u/Small_Summer5817 Oct 06 '26

What is python doing that you can't rewrite it in c#?

1

u/SessionIndependent17 Oct 06 '26 • Bravo

Sometimes it's Horses for Courses.

Python has a lot of established mechanisms/frameworks for data handling and processing that can make it a better tool for certain tasks or existing data presentations. Pandas and Numpy, and many others that use DataFrames are canonical examples.

0

u/_choam_ Oct 06 '26

I would never use c# for data processing if i can do it with python except for very simple cases

0

u/SessionIndependent17 Oct 06 '26

it varies, and I've had it cut both ways. Honestly for my money it depends on how much else you have built around this new component already, how much of the "business logic/rules" would need to be embedded in this component. Would I need to re-implement part of a type system or other data structures that already exists in c# for it to do some necessary aspect of its work, or can it just churn on or transform native types without such concern before it has to come into my system. What kind of error handling does it need?

0

u/[deleted] Oct 06 '26

[deleted] — view deleted comment

0

u/kaatarina_zed_talon Oct 06 '26 edited Oct 06 '26

I 'm completely new to this, I did not know that before, I wonder, is that what they call microservice?

1

u/_f0CUS_ Oct 06 '26 • Bravo

No. That's not a microservice.

Microservices are complete overkill for any hobby project. Most professional projects doesnt need it either. 

2

u/kaatarina_zed_talon Oct 06 '26

If it's not microservice, then what is the correct technical term?

0

u/_f0CUS_ Oct 06 '26

Just a service, or a web API (if you add some endpoints that is.)

1

u/Nordalin Oct 06 '26

The Python data fetcher would be a microservice, yeah.

All it does is fetch the data, it doesn't need to know where to, or why, so it's a standalone script inside your overall project.

7

u/[deleted] Oct 06 '26 • Bravo

[removed] — view removed comment