dwca package#

Package for reading Darwin Core Archive (DwCA) files.

Subpackages#

Module contents#

Darwin Core Base Class#

class dwca.base.darwincore.DarwinCore#

Bases: ABC

Base class of this package.

Methods

from_file(path_to_archive)

Generate a Darwin Core Standard from a file.

to_file(path_to_archive[, encoding])

Generate a Darwin Core file using the information of this instance.

abstract classmethod from_file(path_to_archive: str) DarwinCore#

Generate a Darwin Core Standard from a file.

Parameters:
path_to_archivestr

Path of the archive file.

Returns:
DarwinCore

Instance of the Darwin Core Standard.

abstract to_file(path_to_archive: str, encoding: str = 'utf-8') None#

Generate a Darwin Core file using the information of this instance.

Parameters:
path_to_archivestr

Path of the archive to generate.

encodingstr, optional

Encoding of the corresponding files. Default “utf-8”.

Darwin Core Archive Class#

class dwca.base.darwincore_archive.DarwinCoreArchive(_id: str = None)#

Bases: DarwinCore

Represent a Darwin Core Archive file with all its elements.

Parameters:
_idstr, optional

A unique id for this Darwin Core Archive.

Attributes:
core

DataFile: The file with the core of the archive.

extensions

List[DataFile]: A list with the extension of the archive.

id

str: A unique identifier for this DarwinCoreArchive.

language

Language: Language of the Darwin Core Archive register on metadata.

metadata

EML: Metadata instance, currently supported EML.

Methods

Metadata([metadata])

Metadata class of the Darwin Core Archive storing the file name of the archive elements.

from_file(path_to_archive)

Generate a Darwin Core Archive instance from an archive file (.zip).

generate_eml([filename])

Generate an EML file on the archive

to_file(path_to_archive[, encoding])

Generate a Darwin Core Archive file (.zip file) using the information of this instance.

class Metadata(metadata: str = None)#

Bases: XMLObject

Metadata class of the Darwin Core Archive storing the file name of the archive elements.

Parameters:
metadatastr, optional

Name of the metadata file (e.g.: eml.xml)

Attributes:
NAMESPACE_TAG

Methods

check_principal_tag(tag, nmap)

Checks if the tag is the Principal tag of the object.

from_string(text)

Generates XML Object from a string of an XML file.

from_xml(file[, encoding])

Generates an XML Object from an XML file.

get_dwc_class(element)

Extract the row type from an XML element instance.

get_principal_tag()

Returns the principal tag with namespaces if it is present.

object_to_element(tag[, prefix])

Generates an element using tag, adding namespace tag.

parse(element, nmap)

Parses an lxml.etree.Element in a Metadata instance.

to_element()

Generate an element from a Metadata instance.

to_xml()

Generates text of an XML file.

PRINCIPAL_TAG = 'archive'#

str : Require tag of the metadata

classmethod get_dwc_class(element: Element) Type[DataFile]#

Extract the row type from an XML element instance.

Parameters:
elementlxml.etree.Element

XML element instance.

Returns:
Type[DataFile]

The Python class representing the class term.

classmethod parse(element: Element, nmap: Dict) Metadata#

Parses an lxml.etree.Element in a Metadata instance.

Parameters:
elementlxml.etree.Element

XML element to be parsed.

nmapDict

Namespace prefix:uri.

Returns:
Metadata

New Metadata instance with the data from the element.

to_element() Element#

Generate an element from a Metadata instance.

Returns:
lxml.etree.Element

XML element from Metadata instance

property core: DataFile#

DataFile: The file with the core of the archive.

property extensions: List[DataFile]#

List[DataFile]: A list with the extension of the archive.

classmethod from_file(path_to_archive: str) DarwinCoreArchive#

Generate a Darwin Core Archive instance from an archive file (.zip).

Parameters:
path_to_archivestr

Path of the archive file.

Returns:
DarwinCoreArchive

Instance of the Darwin Core Archive.

generate_eml(filename: str = 'eml.xml') None#

Generate an EML file on the archive

Parameters:
filenamestr

Filename for the EML file to be generated

property id: str#

str: A unique identifier for this DarwinCoreArchive.

property language: Language#

Language: Language of the Darwin Core Archive register on metadata.

property metadata: EML#

EML: Metadata instance, currently supported EML.

to_file(path_to_archive: str, encoding: str = 'utf-8') None#

Generate a Darwin Core Archive file (.zip file) using the information of this instance.

Parameters:
path_to_archivestr

Path of the archive to generate.

encodingstr, optional

Encoding of the corresponding files. Default “utf-8”.

Simple Darwin Core Class#

class dwca.base.simple_darwincore.SimpleDarwinCore#

Bases: DarwinCore

Class representing a Simple Darwin Core standard.

Methods

from_file(path_to_archive)

Generate a Darwin Core Standard from a file.

to_file(path_to_archive[, encoding])

Generate a Darwin Core file using the information of this instance.

classmethod from_file(path_to_archive: str) SimpleDarwinCore#

Generate a Darwin Core Standard from a file.

Parameters:
path_to_archivestr

Path of the archive file.

Returns:
DarwinCore

Instance of the Darwin Core Standard.

to_file(path_to_archive: str, encoding: str = 'utf-8') None#

Generate a Darwin Core file using the information of this instance.

Parameters:
path_to_archivestr

Path of the archive to generate.

encodingstr, optional

Encoding of the corresponding files. Default “utf-8”.