Package: pycgmes
PyCGMESPyCGMESAbout CGMESLibrary usageCustom attributesAdd to an existing profileCreate a new profileImplementation detailsApparent classNamespaceClass/Resource NamespaceAttribute namespaceContent of this repositorySchemas v3SHACL filesV3 source zipDataclassesLibrary build, CI, CD...CICDLicenseContributingContactAttributionPython dataclasses for CGMES 3 + RDF schema description + SHACL (validation) files.About CGMESThe Common Grid Model Exchange Specification, or CGMES, is provided by ENTSO-E (the European Network of TSOs for
Electricity) to facilitate the exchange of grid data between parties. It is based on CIM, the Common Information Model
for electric utilities, provided by the IEC (see alsoCIM on Wikipedia).CIM defines the vocabulary for electricity grids, meaning the names we use for different components and the way they
relate to each other. CGMES takes a subset of this vocabulary and provides RDF schema and SHACL validation files.Further reading and all relevant CGMES (source) files are found onthe CGMES page of the ENTSO-E website.Library usageFrom Pypi.org, 2 packages are available (both from this repository):https://pypi.org/project/pycgmes/https://pypi.org/project/pycgmes-shacl/They can easily be installed via pip:pip install pycgmesorpip install pycgmes-shacl.Custom attributesYou might want to add extra attributes. For instance, the color of a cable (ACLineSegment). This is possible in 2 ways:Adding the attribute to a custom class in an existing profile.Define a new profile including a custom class where the attribute is defined.You can look at theexamplesAdd to an existing profileIf you need to add your own attributes (example: cable colour), you can do that by subclassing the relevant class, and
add one or more new atributes there.If this is a leaf node (for instanceACLineSegment), it "just works". If you want to add an extra attribute to a
class higher in the hierarchy (for instanceEquipment) there is a lot more work to do.@dataclassclassCustomBay(Bay):colour:str=Field(default="Red",in_profiles=[Profile.EQ,],)Create a new profileThis approach is cleaner and more standard compliant: the official CGMES profiles stay untouched, while a new additional profile contains your customisations.You can do this by extending the `BaseProfile`` Enum inprofile.py.While in Python it is not possible to extend or compose Enums which already have fields, you can create your own:frompycgmes.utils.profileimportBaseProfileclassCustomProfile(BaseProfile):CUS="Tom"FRO="Mage"And use it everywhere you would use a profile:@dataclassclassCustomBayAttr(Bay):colour:str=Field(default="Red",json_schema_extra={"in_profiles":[CustomProfile.CUS,],})# And for instance:custom_attrs=CustomBayAttr(colour="purple").cgmes_attributes_in_profile(CustomProfile.CUS)Implementation detailsApparent classBy default, an attribute is fully qualified. A standardattributeinACLineSegmentwill appear asACLineSegment.attributein the serialisation.
In the case of a custom attribute defined via a sub class, the result would be:ACLineSegmentCustom.customAttribute. To preserve the original class name (i.e. serialise your attribute asACLineSegment.customAttribute), you need to override theapparent_nameof your custom class:frompydantic.dataclassesimportdataclassfrompycgmes.resources.ACLineSegmentimportACLineSegment@dataclassclassACLineSegmentCustom(ACLineSegment):@classmethoddefapparent_name(cls):return"ACLineSegment"NamespaceClass/Resource NamespaceThe default class (or resource) namespace ishttp://iec.ch/TC57/CIM100#.You can override it when you create a custom resource by just redefining the propertynamespace:Attribute namespaceIn the serialisation, the namespace of all attributes ishttp://iec.ch/TC57/CIM100#by default.The namespace of an attribute is the first value found:namespace defined in the Field (seecolourbelow - it would becustom)namespace of the class (seesizebelow - it would becustom ns class)namespace of the first parent defining one. The top parent (Base) definedcim.frompydantic.dataclassesimportdataclassfrompydanticimportFieldfrompycgmes.resourcesimportACLineSegment@dataclassclassACLineSegmentCustom(ACLineSegment):colour:str=Field(default="Red",json_schema_extra={"in_profiles":[Profile.EQ,# Do not do this, see chapter "create a new profile"],"namespace":"custom",},)size:str=Field(default="Big",json_schema_extra={"in_profiles":[Profile.EQ,# Do not do this, see chapter "create a new profile"],})@propertydefnamespace(self)->str:return"custom ns class"@classmethoddefapparent_name(cls):return"ACLineSegment"It will be given whencgmes_attributes_in_profile()is called.Content of this repositorySchemas v3schemasare rdf definitions of CGMES. They are used once, to generate dataclasses, and
can then happily be forgotten.They are available on theENTSO-E site.
Look for CGMES Conformity Assessment Scheme v3
thenApplication Profiles v3.0.1Older versions could be found on theENTSO-E site.SHACL filesShapes Constraint Languageis used for validation of the actual content of the
CGMES files, not just XML validation. They can be found inshacl. This is the new validation
standard. OCL
is referenced, specially with older versions, but ENTSO-E is moving away from it.To use them, there is another packagepycmges-shacl, built from this repo as well.V3 source zipFrom ENTSO-E, indata. This is one small-ish zip file, containing a bit more than just the SHACL and RDFS
files (those extracted and mentioned above) but is usually not needed.DataclassesGenerated from the modernpython serialisation ofcimgen.Library build, CI, CD...CIThe CI happens in GitHub actions.The standard black/pyright/ruff are run there, via scons.CDDeployment happens to pypi.org, via the standard poetry commandspoetry build,poetry publish.LicenseThis project is licensed under the Apache 2.0 license - seeLICENSEfor details.ContributingPlease readCODE_OF_CONDUCT.md,CONTRIBUTING.md, andPROJECT GOVERNANCE.mdfor details on the process for submitting pull requests to us.ContactPlease readSUPPORT.mdfor how to connect and get into contact with the project.AttributionThis project represents an advanced evolution of two prior initiatives: CIMgen and CIMpy. For further details and insights into the foundational work that inspired this project, interested parties are encouraged to visit their respective repositories on GitHub. CIMgen can be accessed atCIMgen GitHub Repository, and CIMpy atCIMpy GitHub Repository.