Abstract class for Python internal interfaces¶
This class contains common functionality of interfaces to packages that can be installed (using pip) as a Python library (called a Python-CAS in the sequel) such as Regina or SnapPy.
AUTHORS:
Sebastian Oehms (2026): first version (refactored from regina.py)
- class sage.interfaces.python_internal.PythonInternalElement(parent, value, is_name=False, name=None)[source]¶
Bases:
ExtraTabCompletion,InterfaceElementElement class of the Python internal interface.
Its instances are usually constructed via the instance call of its parent. It wrapes the Python internal library for this object. In a session Python internal methods can be obtained using tab completion.
EXAMPLES:
sage: b = BraidGroup(3)((1,2,-1)) sage: re = regina(b); re <regina.GroupExpression: g0 g1 g0^-1> sage: type(re) <class 'sage.interfaces.regina.ReginaElement'> sage: P = re.parent(); P Regina sage: type(P) <class 'sage.interfaces.regina.Regina'>
>>> from sage.all import * >>> b = BraidGroup(Integer(3))((Integer(1),Integer(2),-Integer(1))) >>> re = regina(b); re <regina.GroupExpression: g0 g1 g0^-1> >>> type(re) <class 'sage.interfaces.regina.ReginaElement'> >>> P = re.parent(); P Regina >>> type(P) <class 'sage.interfaces.regina.Regina'>
Access to the Python-CAS expression objects:
sage: res = re._inst sage: type(res) <class 'regina.engine.GroupExpression'>
[Python]>>> from sage.all import * >>> res = re._inst >>> type(res) <class 'regina.engine.GroupExpression'>
Applying Python-CAS methods:
sage: re.cycleLeft(); re <regina.GroupExpression: g0^-1 g0 g1>
>>> from sage.all import * >>> re.cycleLeft(); re <regina.GroupExpression: g0^-1 g0 g1>
Conversion to Sage:
sage: re.sage() == b False sage: re.cycleRight() sage: re.sage() == b True
[Python]>>> from sage.all import * >>> re.sage() == b False >>> re.cycleRight() >>> re.sage() == b True
- class sage.interfaces.python_internal.PythonInternalFunction(parent, name)[source]¶
Bases:
InterfaceFunctionInterface Function.
EXAMPLES:
sage: m = regina.MatrixInt; m <class 'regina.engine.MatrixInt'> sage: type(m) <class 'sage.interfaces.python_internal.PythonInternalFunction'>
>>> from sage.all import * >>> m = regina.MatrixInt; m <class 'regina.engine.MatrixInt'> >>> type(m) <class 'sage.interfaces.python_internal.PythonInternalFunction'>
- class sage.interfaces.python_internal.PythonInternalFunctionElement(obj, name)[source]¶
Bases:
InterfaceFunctionElementInterface methods of interface elements.
EXAMPLES:
sage: A = regina.AbelianGroup() sage: type(A.addRank) <class 'sage.interfaces.python_internal.PythonInternalFunctionElement'> sage: M = snappy.Manifold('9_42') sage: M.DT_code <bound method Triangulation.DT_code of 9_42(0,0)> sage: type(M.DT_code) <class 'sage.interfaces.python_internal.PythonInternalFunctionElement'>
>>> from sage.all import * >>> A = regina.AbelianGroup() >>> type(A.addRank) <class 'sage.interfaces.python_internal.PythonInternalFunctionElement'> >>> M = snappy.Manifold('9_42') >>> M.DT_code <bound method Triangulation.DT_code of 9_42(0,0)> >>> type(M.DT_code) <class 'sage.interfaces.python_internal.PythonInternalFunctionElement'>
- class sage.interfaces.python_internal.PythonInternalInterface(name)[source]¶
Bases:
ExtraTabCompletion,InterfacePython internal interface.
EXAMPLES:
sage: K = Knots().from_table(8, 21) sage: Kr = regina(K); Kr <regina.Link: 8-crossing knot: ----++-- ( _5 _0 ^1 _2 _3 ^6 _7 ^3 _4 ^5 _6 ^7 ^0 _1 ^2 ^4 )> sage: Kr.knotSig() 'iabcdbefcdghaefghRsgF+m'
>>> from sage.all import * >>> K = Knots().from_table(Integer(8), Integer(21)) >>> Kr = regina(K); Kr <regina.Link: 8-crossing knot: ----++-- ( _5 _0 ^1 _2 _3 ^6 _7 ^3 _4 ^5 _6 ^7 ^0 _1 ^2 ^4 )> >>> Kr.knotSig() 'iabcdbefcdghaefghRsgF+m'
More examples can be found in the module header.
- eval(code, *args, **kwds)[source]¶
Evaluates a command inside the Python-CAS interpreter and returns the output in printable form.
EXAMPLES:
sage: regina.eval('1+1') '2'
>>> from sage.all import * >>> regina.eval('1+1') '2'
- get(var)[source]¶
Get the value of the variable
var.EXAMPLES:
sage: regina.get('Link') <class 'regina.engine.Link'> sage: snappy.get('Triangulation') <class 'SnapPy.Triangulation'>
>>> from sage.all import * >>> regina.get('Link') <class 'regina.engine.Link'> >>> snappy.get('Triangulation') <class 'SnapPy.Triangulation'>
- help(cmd, long=False)[source]¶
Return the documentation of the given command via the Python internal interface.
EXAMPLES:
sage: regina.help('AbelianGroup') Represents a finitely generated abelian group. The torsion elements of the group are stored in terms of their invariant factors. For instance, Z_2+Z_3 will appear as Z_6, and Z_2+Z_2+Z_3 will appear as Z_2+Z_6. In general the factors will appear as Z_*d0*+...+Z_*dn*, where the invariant factors *di* are all greater than 1 and satisfy *d0*|*d1*|...|*dn*. Note that this representation is unique. This class implements C++ move semantics and adheres to the C++ Swappable requirement. It is designed to avoid deep copies wherever possible, even when passing or returning objects by value. sage: snappy.help('AbelianGroup') An AbelianGroup object represents a finitely generated abelian group, usually the first homology group of a snappy Manifold. Instantiate an abelian group by its elementary divisors: ...
>>> from sage.all import * >>> regina.help('AbelianGroup') Represents a finitely generated abelian group. <BLANKLINE> The torsion elements of the group are stored in terms of their invariant factors. For instance, Z_2+Z_3 will appear as Z_6, and Z_2+Z_2+Z_3 will appear as Z_2+Z_6. <BLANKLINE> In general the factors will appear as Z_*d0*+...+Z_*dn*, where the invariant factors *di* are all greater than 1 and satisfy *d0*|*d1*|...|*dn*. Note that this representation is unique. <BLANKLINE> This class implements C++ move semantics and adheres to the C++ Swappable requirement. It is designed to avoid deep copies wherever possible, even when passing or returning objects by value. >>> snappy.help('AbelianGroup') <BLANKLINE> An AbelianGroup object represents a finitely generated abelian group, usually the first homology group of a snappy Manifold. <BLANKLINE> Instantiate an abelian group by its elementary divisors: ...
- set(var, value)[source]¶
Set the variable
varto the givenvalue.EXAMPLES:
sage: regina.set('myLink', 'Link') sage: regina.get('myLink') <class 'regina.engine.Link'> sage: snappy.set('K9_15', 'Link("9_15")') sage: snappy.get('K9_15') <Link 9_15: 1 comp; 9 cross>
>>> from sage.all import * >>> regina.set('myLink', 'Link') >>> regina.get('myLink') <class 'regina.engine.Link'> >>> snappy.set('K9_15', 'Link("9_15")') >>> snappy.get('K9_15') <Link 9_15: 1 comp; 9 cross>