|pypi-version| |master-build| |coverage| |code-quality| |license|
.. |master-build| image:: https://travis-ci.org/pyecore/pyecore.svg?branch=master :target: https://travis-ci.org/pyecore/pyecore
.. |develop-build| image:: https://travis-ci.org/pyecore/pyecore.svg?branch=develop :target: https://travis-ci.org/pyecore/pyecore
.. |pypi-version| image:: https://badge.fury.io/py/pyecore.svg :target: https://badge.fury.io/py/pyecore
.. |coverage| image:: https://coveralls.io/repos/github/pyecore/pyecore/badge.svg?branch=master :target: https://coveralls.io/github/pyecore/pyecore?branch=master
.. |license| image:: https://img.shields.io/badge/license-New%20BSD-blue.svg :target: https://raw.githubusercontent.com/pyecore/pyecore/master/LICENSE
.. |code-quality| image:: https://api.codacy.com/project/badge/Grade/ed038354821f43e7a4579c6a14185cdf :target: https://www.codacy.com/app/aranega/pyecore
PyEcore is a Model Driven Engineering (MDE) framework written for Python.
Precisely, it is an implementation of EMF/Ecore <https://www.eclipse.org/modeling/emf/>
_ for Python, and it tries to give an
API which is compatible with the original EMF Java implementation.
PyEcore allows you to handle models and metamodels (structured data model), and gives the key you need for building MDE-based tools and other applications based on a structured data model. It supports out-of-the-box:
Let's see how we can create a very simple "dynamic" metamodel (as opposed to
static ones, see the documentation <https://pyecore.readthedocs.io/en/latest/>
_
for more details):
.. code-block:: python
>>> from pyecore.ecore import EClass, EAttribute, EString, EObject
>>> Graph = EClass('Graph') # We create a 'Graph' concept
>>> Node = EClass('Node') # We create a 'Node' concept
>>>
>>> # We add a "name" attribute to the Graph concept
>>> Graph.eStructuralFeatures.append(EAttribute('name', EString,
default_value='new_name'))
>>> # And one on the 'Node' concept
>>> Node.eStructuralFeatures.append(EAttribute('name', EString))
>>>
>>> # We now introduce a containment relation between Graph and Node
>>> contains_nodes = EReference('nodes', Node, upper=-1, containment=True)
>>> Graph.eStructuralFeatures.append(contains_nodes)
>>> # We add an opposite relation between Graph and Node
>>> Node.eStructuralFeatures.append(EReference('owned_by', Graph, eOpposite=contains_nodes))
With this code, we have defined two concepts: Graph
and Node
. Both have
a name
, and there exists a containment relationship between them. This relation
is bi-directional, which means that each time a Node
object is added to the
nodes
relationship of a Graph
, the owned_by
relation of the Node
is also updated (it also works the other way around).
Let's create some instances of our freshly created metamodel:
.. code-block:: python
>>> # We create a Graph
>>> g1 = Graph(name='Graph 1')
>>> g1
<pyecore.ecore.Graph at 0x7f0055554dd8>
>>>
>>> # And two node instances
>>> n1 = Node(name='Node 1')
>>> n2 = Node(name='Node 2')
>>> n1, n2
(<pyecore.ecore.Node at 0x7f0055550588>,
<pyecore.ecore.Node at 0x7f00555502b0>)
>>>
>>> # We add them to the Graph
>>> g1.nodes.extend([n1, n2])
>>> g1.nodes
EOrderedSet([<pyecore.ecore.Node object at 0x7f0055550588>,
<pyecore.ecore.Node object at 0x7f00555502b0>])
>>>
>>> # bi-directional references are updated
>>> n1.owned_by
<pyecore.ecore.Graph at 0x7f0055554dd8>
This example gives a quick overview of some of the features you get for free when using PyEcore.
The project slowly grows and it still requires more love.
PyEcore is available on pypi
, you can simply install it using pip
:
.. code-block:: bash
$ pip install pyecore
The installation can also be performed manually (better in a virtualenv):
.. code-block:: bash
$ python setup.py install
You can read the documentation at this address:
https://pyecore.readthedocs.io/en/latest/
The dependencies required by pyecore are:
ordered
and unique
collections expressed in the metamodel,These dependencies are directly installed if you choose to use pip
.
The tests use py.test
and 'coverage'. Everything is driven by Tox
, so in order
to run the tests simply run:
.. code-block:: bash
$ tox
In the current state, the project implements:
-1
),xsi:schemaLocation
support for XMI resources,EGeneric
support (first simple version),The things that are in the roadmap:
EOrderedSet
, EList
, ESet
and EBag
,EStringToStringMapEntry
and EFeatureMapEntry
,There aren't too many projects proposing to handle models and metamodels in Python. The only projects I found are:
PyEMOF proposes an implementation of the OMG's EMOF in Python. The project targets Python2, only supports Class/Primitive Types (no Enumeration), XMI import/export and does not provide a reflexion layer. The project didn't move since 2005.
EMF4CPP proposes a C++ implementation of EMF. This implementation also introduces Python scripts to call the generated C++ code from a Python environment. It seems that the EMF4CPP does not provide a reflexive layer either.
PyEMOFUC proposes, like PyEMOF, a pure Python implementation of the OMG's EMOF. If we stick to a kind of EMF terminology, PyEMOFUC only supports dynamic metamodels and seems to provide a reflexive layer. The project does not appear to have moved since a while.
Thanks for making PyEcore better!
@moltob <https://github.com/moltob>
), who is also the author
of pyecoregen <https://github.com/pyecore/pyecoregen>
and pymultigen <https://github.com/moltob/pymultigen>
_ (on which pyecoregen is based)@TerryKingston <https://github.com/TerryKingston>
_)@afonsobspinto <https://github.com/afonsobspinto>
_)@CFAndy <https://github.com/CFAndy>
_)@annighoefer <https://github.com/annighoefer>
_)@rodriguez-facundo <https://github.com/rodriguez-facundo>
_)@filippometacell <https://github.com/filippometacell>
_)@ewoudwerkman <https://github.com/ewoudwerkman>
_)@4ekin <https://github.com/4ekin>
_)@aacebedo <https://github.com/aacebedo>
_)@jinhu <https://github.com/jinhu>
_)@pablo-campillo <https://github.com/pablo-campillo>
_)@jamoralp <https://github.com/jamoralp>
_)@ubmarco <https://github.com/ubmarco>
_)@cdrabek <https://github.com/cdrabek>
_)@danyeaw <https://github.com/danyeaw>
_)@arrys <https://github.com/arrys>
_)This article <http://modeling-languages.com/pyecore-python-eclipse-modeling-framework>
_
on the blog of Professor Jordi Cabot gives more information and
implementation details about PyEcore.