Skip to content

CreateWork

CreateWork

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.

Parameters:

Name Type Description Default
directory Optional[str]

A directory path where you would like to save your work.

None
metadata Optional[WorkMetadata]

A model defined by a dictionary of terms.

None
stateless bool

Whether your workflow is stateless (default False).

False
Example

Create a new work as follows:

from chapisha.create import CreateWork

work = CreateWork(directory, metadata=metadata, stateless=True)

add_contributor(contributor)

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

Example

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

Parameters:

Name Type Description Default
contributor Contributor

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

required

Raises:

Type Description
PermissionError

if metadata not yet validated.

build()

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

get_metadata_schema()

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

Returns:

Type Description
dict

A dictionary definition of the metadata.

set_cover(source, contributor=None)

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:

Name Type Description Default
source Path | bytes

Filename to open, including path, or bytes for file

required
contributor Optional[Contributor]

Optional, string indicating contributor name for cover image.

None

Raises:

Type Description
PermissionError

If metadata not yet validated.

FileNotFoundError

If the source is not valid.

set_dedication(dedication)

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

Parameters:

Name Type Description Default
dedication str | list[str]

Provide as a string, or list of strings for multiple paragraphs.

required

set_document(source)

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:

Name Type Description Default
source Path | bytes | str

Filename to open, bytes from an opened file, or a base64 string

required

Raises:

Type Description
PermissionError

If metadata not yet validated.

FileNotFoundError

If the source is not valid.

set_metadata(metadata)

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:

Name Type Description Default
metadata WorkMetadata

A model defined by a dictionary of terms.

required

Returns:

Type Description
bool

Boolean response on acceptance.

set_rights(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:

Name Type Description Default
rights str | list[str]

Provide as a string, or list of strings for multiple paragraphs.

required

validate()

Validate the creative work as a standards compliant EPUB3.

Returns:

Type Description
bool

Boolean True if validates.