\usemodule[filter]

\defineexternalfilter 
  [sympy]
  [filtercommand={python \externalfilterinputfile\space > \externalfilteroutputfile},
   bufferbefore=init]

\startbuffer[init]
from sympy import apart
from sympy.abc import x
\stopbuffer

\starttext
\startsympy
print(apart( (x+1)/(x-1), x))
\stopsympy

Or if you want fancy formating

\defineexternalfilter
  [sympycalc]
  [filtercommand={python \externalfilterinputfile\space > \externalfilteroutputfile},
   bufferbefore=init,
   readcommand=\DisplayCalcFile]

\usemodule[calcmath]
\unexpanded\def\DisplayCalcFile#1{\ctxlua{thirddata.displaycalcfile("#1")}}

\startluacode
  thirddata = thirddata or {}

  local calc = moduledata.calcmath.tex
  
  thirddata.displaycalcfile = function (filename)
    local data = file.readdata(filename)
    print(data)
    calc(data)
  end
\stopluacode

\startsympycalc
print(apart( (x+1)/(x-1), x))
\stopsympycalc
\stoptext

