GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - OpenMath/py-openmath: An OpenMath 2.0 implementation in Python

BranchesTags
Open more actions menu

Latest commit

 

History

107 Commits
107 Commits

Folders and files

NameName
Last commit message
Last commit date
openmath
openmath
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.rst
README.rst
 
 
example.py
example.py
 
 
requirements.txt
requirements.txt
 
 
setup.cfg
setup.cfg
 
 
setup.py
setup.py
 
 

Repository files navigation

pyopenmath

Build Status Pypi

Python OpenMath 2.0 implementation.

Description

OpenMath is an extensible standard for representing the semantics of mathematical objects.

Installation

pip install openmath

Usage

This package provides an object implementation of OpenMath, and XML parsing/serialization.

See py-scscp for an example of use.

XML Serialization

The modules encoder and decoder provide XML de-serialization for OpenMath objects.

>>> from openmath import encoder, decoder, openmath as om
>>> xml = encoder.encode_xml(om.OMString('hello world')); xml
<Element {http://www.openmath.org/OpenMath}OMSTR at 0x7fcb3cd82708>
>>> b = encoder.encode_bytes(om.OMString('hello world')); b
b'<OMSTR xmlns="http://www.openmath.org/OpenMath">hello world</OMSTR>'
>>> decoder.decode_xml(xml)
OMString('hello world', id=None)
>>> decoder.decode_bytes(b, snippet=True)
OMString('hello world', id=None)

Conversions between Python and OpenMath

This package provides facilities for easy conversions from Python to OpenMath and back. The module convert contains a Converter class, which is used to implements this functionality. For convenienve, an instance of this class, DefaultConverter is provided.

The two functions to_python() and to_openmath() do the conversion as their names suggest, or raise a ValueError if no conversion is known.

By default, a Converter only implements conversions for basic Python types:

  • bools,
  • ints,
  • floats,
  • complex numbers,
  • strings,
  • bytes,
  • lists (recursively),
  • sets (recursively).

Furthermore, any object that defines an __openmath__(self) method will have that method called by to_python.

Finally, this class contains a mechanism for registering converters.

>>> from fractions import Fraction
>>> from openmath import openmath as om
>>> from openmath.convert import DefaultConverter as converter
>>> def to_om_rat(obj):
...     return om.OMApplication(om.OMSymbol('rational', cd='nums1'),
...                             list(map(converter.to_openmath, [obj.numerator, obj.denominator])))
...
>>> def to_py_rat(obj):
...     return Fraction(converter.to_python(obj.arguments[0]), converter.to_python(obj.arguments[1]))
...
>>> converter.register(Fraction, to_om_rat, 'nums1', 'rational', to_py_rat)
>>> omobj = converter.to_openmath(Fraction(5, 6)); omobj
OMApplication(OMSymbol('rational', 'nums1', id=None, cdbase=None), [OMInteger(5, id=None), OMInteger(6, id=None)], id=None, cdbase=None)
>>> converter.to_python(omobj)
Fraction(5, 6)

Contributing

The source code of this project can be found on GitHub. Please use GitHub issues and pull requests to contribute to this project.

Credits

This work is supported by OpenDreamKit.

License

This work is licensed under the MIT License, for details see the LICENSE file.

About

An OpenMath 2.0 implementation in Python

Resources

Readme
License
Activity
Custom properties

Stars

17 stars

Watchers

5 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.