Skip to main content

Generate Python data structures from CIM RDF profiles, parse and serialize CIM-compliant information objects, according to IEC 61970-501 standard

Project description

cimrdf.py

Generate Python data structures from CIM RDF profiles, parse and serialize CIM-compliant information objects, according to IEC 61970-501 standard.

Installing

$ pip install cimrdf.py

or

$ git clone https://github.com/bressanmarcos/cimrdf.py.git
$ cd cimrdf.py
$ python setup.py install 

Using

  1. Create your CIM RDF artifact with your preferred utils
  2. Convert it into Python data structures with:
cimrdfpy input-rdfs.xml output.py

Creating CIM RDF instances

3a. Use the generated classes from output.py to create your instances

from output import *

ei = EquivalentInjection()
ei.mRID = 'EquivalentNW243'
t = Terminal()
t.sequenceNumber = 1
# This next command reciprocally associates the `t` Terminal to `ei` EquivalentInjection,
t.ConductingEquipment = ei
# but only if this association is well-defined in the RDFS document (inverseRoleName property).

t1 = Terminal(sequenceNumber=1)
t2 = Terminal()
t2.sequenceNumber = 2
s = Switch(mRID='SW12', normalOpen=True)
# All attributes with multiplicity greater than 1 are represented as lists
s.add_Terminals(t1)
# A special function `add_{attribute_name}` is generated to insert a single item into the list
s.add_Terminals(t2)

cn = ConnectivityNode()
cn.mRID = 'Node23'
# List-type attributes may also be declared in the following way:
cn.Terminals = [t1, t] 

4a. Create a new document instance with all objects

new_doc = DocumentCIMRDF()
new_doc.add_recursively(ei)
# >> All other linked objects will be automatically inserted into the document

The available methods for the DocumentCIMRDF class are:

  • new_doc.dump(): Pretty-Print the document to stdout. Debug purposes only.
  • new_doc.pack(): Generate the document's ElementTree (xml.etree.ElementTree) instance.
  • new_doc.tostring(): Get the XML stringified version of the document.
  • new_doc.tofile(): Save the XML stringified version of the document to a file.
  • new_doc.add_elements( ... ): (Advanced users only) Insert one or a list of elements into the document.
  • new_doc.add_recursively( ... ): (Recommended) Insert one or a list of elements into the document including its linked elements.

Parsing CIM RDF instances

3b. Use proper functions to parse a file or a string.

new_doc = DocumentCIMRDF()
new_doc.fromstring(rdfstring)
print(new_doc.resources)
# >> [list of instances]

The available functions are:

  • new_doc.fromstring(rdfstring): Get list of instances from CIM RDF string.
  • new_doc.fromfile(filename): Get list of instances from CIM RDF file.

After being inserted or parsed from a string/file, the elements are stored and accessible from the new_doc.resources attribute.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cimrdf.py-2.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

cimrdf.py-2.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file cimrdf.py-2.1.tar.gz.

File metadata

  • Download URL: cimrdf.py-2.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for cimrdf.py-2.1.tar.gz
Algorithm Hash digest
SHA256 959524c11099021cd7717d59a9c4fad824b009bec9d47fdaf3f510048465824a
MD5 52bd4bbc12205024394ea4b5b5d95647
BLAKE2b-256 4843a3952675ad89460a180ddcac1a9df63e874417824390b7dcc484b890b94e

See more details on using hashes here.

File details

Details for the file cimrdf.py-2.1-py3-none-any.whl.

File metadata

  • Download URL: cimrdf.py-2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for cimrdf.py-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb14cc038832522fbaaf1f30f00fd310f2accb66c9fe2ad2a5c0ad5fb9ea16a2
MD5 545323ef91221dd0d776e6e2c94e304a
BLAKE2b-256 d908c807662f778f39070c2a51c054db0fdbc0ea4beee2f51f2779a6afac5587

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page