CreateWork

The CreateWork class defines the steps for creating an epub.

class chapisha.create.CreateWork(directory: Optional[str] = None, metadata: Optional[chapisha.models.metadata.WorkMetadata] = None, stateless: bool = False)

Publish a standards compliant EPUB3 creative work from a source Microsoft Word docx document, and define its metadata, cover and publishing rights.

If the EPUB file already exists, then publishing this work will overwrite it.

On instantiation, checks directory to see if DEFAULT_METADATA_SETTINGS is present, loading the required data, or replacing with specified defaults.

get_metadata_schema() dict

Return the standard Dublin Core schema permitted for the EPUB3 standard.

Returns

Return type

dict

set_metadata(metadata: chapisha.models.metadata.WorkMetadata) bool

Validate metadata values for the permitted Dublin Core schema terms, along with additional metadata. The full schema, with descriptions, and requirements, is listed by get_metadata_schema.

Note

The terms identifier, title, creator, rights and language are required. A random UUID will be assigned if none is provided.

Parameters

metadata (WorkMetadata) – A model defined by a dictionary of terms.

Returns

Return type

bool

set_document()

Import source docx document and, if stateless, save to the working directory. If you’re finding errors in the build step, it could be you need to convert your base64 string to “utf-8” (source.decode(“utf-8”)).

Parameters

source (Path, bytes, or str) – Filename to open, bytes from an opened file, or a base64 string

Raises
  • PermissionError – if metadata not yet validated.:

  • FileNotFoundError – if the source is not valid.:

set_cover()

Import cover image and, if stateless, save to the working directory, along with any rights and contributor information. If you’re finding errors in the build step, it could be you need to convert your base64 string to “utf-8” (source.decode(“utf-8”)).

Parameters
  • source (Path or bytes) – Filename to open, including path, or bytes for file

  • contributor (Contributor) – Optional, string indicating contributor name for cover image.

Raises
  • PermissionError – if metadata not yet validated.:

  • FileNotFoundError – if the source is not valid.:

add_contributor(contributor: chapisha.models.metadata.Contributor)

Add a contributor to the list of those supporting the creation of the work. contributor is defined as a dict:

contributor = {
    "role": "artist",
    "name": "Great Artist",
    "year": "2021",
    "terms": "Public Domain."
}
Parameters

contributor (Contributor) – Include the types of contributor who supported the creation of the work. role: artist, editor, translator.

Raises

PermissionError – if metadata not yet validated.:

set_dedication()

Set dedication page for creative work. Provide as a string, unless it is on multiple paragraphs.

Parameters

dedication (str or list of str) – Provide as a string, or list of strings for multiple paragraphs.

set_rights()

Set publication long_rights for creative work. Provide as a string, or list of strings if it is on multiple paragraphs.

There are multiple appropriate rights, and two examples are below. Modify as you require.

  • Commercial copyright with all rights reserved:

    The right of the creator to be identified as the author of the Work has been asserted by them in accordance with the Copyright, Designs and Patents Act 1988. This creator supports copyright. Copyright gives creators space to explore and provides for their long-term ability to sustain themselves from their work. Thank you for buying this work and for complying with copyright laws by not reproducing, scanning, or distributing any part of it without permission. Your support will contribute to future works by the creator.

  • Commercial copyright but licenced for distribution under Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0):

    You are free to copy and redistribute the Work in any medium or format, and remix, transform, and build upon the Work. The creator cannot revoke these freedoms as long as you follow the license terms.

    In return: You may not use the material for commercial purposes. You must give appropriate credit, provide a link to this license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the creator endorses you or your use. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Parameters

rights (str or list of str) – Provide as a string, or list of strings for multiple paragraphs.

build()

Automatically build the creative work as a standards compliant EPUB3. Save to the root directory.

validate() bool

Validate the creative work as a standards compliant EPUB3.