zenodo

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

README

go-zenodo

go.dev reference Go Report Card License

go-zenodo is a simple (and incomplete) Go client for Zenodo, following its REST API documented there.

Installation

$> go install codeberg.org/sbinet/zenodo@latest

Example

func ExampleClient() {
	const (
		token    = "s3cr3t-t0k3n"
		endpoint = "https://zenodo.org"
	)

	cli, err := zenodo.New(endpoint, token, zenodo.WithUserAgent("go-zenodo/v0.0.1"))
	if err != nil {
		log.Fatalf("could not create Zenodo client: %v", err)
	}

	var (
		ctx = context.Background()
		did int
	)

	for dep, err := range cli.Depositions(ctx) {
		if err != nil {
			log.Fatalf("could not iterate over depositions: %v", err)
		}
		fmt.Printf("deposition: id=%d, DOI=%q title=%q", dep.ID, dep.DOI, dep.Title)
		did = dep.ID
	}

	dep, err := cli.Deposition(ctx, did)
	if err != nil {
		log.Fatalf("could not retrieve deposition %d from Zenodo: %v", did, err)
	}
	fmt.Printf("last deposition: id=%d, DOI=%q title=%q", dep.ID, dep.DOI, dep.Title)
}

Documentation

Overview

Package zenodo provides a Go interface to the Zenodo REST API.

More informations on:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessRight

type AccessRight string
const (
	OpenAccess       AccessRight = "open"
	EmbargoedAccess  AccessRight = "embargoed"
	RestrictedAccess AccessRight = "restricted"
	ClosedAccess     AccessRight = "closed"
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Zenodo client.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"codeberg.org/sbinet/zenodo"
)

func main() {
	const (
		token    = "s3cr3t-t0k3n"
		endpoint = "https://zenodo.org"
	)

	cli, err := zenodo.New(endpoint, token, zenodo.WithUserAgent("go-zenodo/v0.0.1"))
	if err != nil {
		log.Fatalf("could not create Zenodo client: %v", err)
	}

	var (
		ctx = context.Background()
		did int
	)
	for dep, err := range cli.Depositions(ctx) {
		if err != nil {
			log.Fatalf("could not iterate over depositions: %v", err)
		}
		fmt.Printf("deposition: id=%d, DOI=%q title=%q", dep.ID, dep.DOI, dep.Title)
		did = dep.ID
	}

	dep, err := cli.Deposition(ctx, did)
	if err != nil {
		log.Fatalf("could not retrieve deposition %d from Zenodo: %v", did, err)
	}
	fmt.Printf("deposition: id=%d, DOI=%q title=%q", dep.ID, dep.DOI, dep.Title)
}
Example (Create)
package main

import (
	"context"
	"fmt"
	"log"

	"codeberg.org/sbinet/zenodo"
)

func main() {
	const (
		token    = "s3cr3t-t0k3n"
		endpoint = "https://zenodo.org"
	)

	cli, err := zenodo.New(endpoint, token)
	if err != nil {
		log.Fatalf("could not create Zenodo client: %v", err)
	}

	meta := zenodo.Metadata{
		Title:       "go-zenodo",
		UploadType:  zenodo.Software,
		Description: "A simple client for Zenodo, in Go",
		Creators:    []zenodo.Creator{{Name: "Jane Doe", Affiliation: "ACME"}},
	}

	ctx := context.Background()

	dep, err := cli.Create(ctx, meta)
	if err != nil {
		log.Fatalf("could not create new deposition: %v", err)
	}
	id := dep.ID
	fmt.Printf("created deposition: id=%d, DOI=%q title=%q", id, dep.DOI, dep.Title)

	meta.Title = "Exciting Go-Zenodo client"

	dep, err = cli.Update(ctx, id, meta)

	_, err = cli.Publish(ctx, dep.ID)
	if err != nil {
		log.Fatalf("could not publish deposition: %v", err)
	}
}

func New

func New(srv, auth string, opts ...Option) (*Client, error)

New creates a zenodo client for the provided zenodo server URL and authentication token.

Example:

cli, err := New("https://zenodo.org", "s3cr3t")

func (*Client) Create

func (cli *Client) Create(ctx context.Context, meta Metadata, files ...fs.File) (Deposition, error)

Create creates a new deposition with the provided metadata and files.

func (*Client) Delete

func (cli *Client) Delete(ctx context.Context, id int) error

Delete deletes the provided deposition. Note that only unpublished depositions may be deleted.

See:

https://developers.zenodo.org/#delete

func (*Client) Deposition

func (cli *Client) Deposition(ctx context.Context, id int) (dep Deposition, err error)

Deposition retrieves the deposition identified by the provided id.

func (*Client) Depositions

func (cli *Client) Depositions(ctx context.Context) iter.Seq2[Deposition, error]

Depositions iterates over all depositions for the current authenticated user.

func (*Client) Discard

func (cli *Client) Discard(ctx context.Context, id int) (dep Deposition, err error)

Discard discards changes in the current editing session.

See:

https://developers.zenodo.org/#discard

func (*Client) Edit

func (cli *Client) Edit(ctx context.Context, id int) (o Deposition, err error)

Edit unlocks an already submitted deposition for edition. See:

https://developers.zenodo.org/#edit

func (*Client) NewVersion

func (cli *Client) NewVersion(ctx context.Context, id int, meta Metadata, files ...fs.File) (o Deposition, err error)

NewVersion creates a new version for the deposition id, with the provided metadata and files.

See:

https://developers.zenodo.org/#new-version

func (*Client) Publish

func (cli *Client) Publish(ctx context.Context, id int) (dep Deposition, err error)

Publish publishes the deposition id.

Note that, once a deposition has been published, it can no longer be deleted. See:

https://developers.zenodo.org/#publish

func (*Client) Update

func (cli *Client) Update(ctx context.Context, id int, meta Metadata) (dep Deposition, err error)

Update updates an existing deposition resource with the provided metadata.

See:

https://developers.zenodo.org/#update

type Contributor

type Contributor string
const (
	ContactPerson         Contributor = "contactperson"
	DataCollector         Contributor = "datacollector"
	DataCurator           Contributor = "datacurator"
	DataManager           Contributor = "datamanager"
	Distributor           Contributor = "distributor"
	Editor                Contributor = "editor"
	HostingInstitution    Contributor = "hostinginstitution"
	Producer              Contributor = "producer"
	ProjectLeader         Contributor = "projectleader"
	ProjectManager        Contributor = "projectmanager"
	ProjectMember         Contributor = "projectmember"
	RegistrationAgency    Contributor = "registrationagency"
	RegistrationAuthority Contributor = "registrationauthority"
	RelatedPerson         Contributor = "relatedperson"
	Researcher            Contributor = "researcher"
	ResearchGroup         Contributor = "researchgroup"
	RightsHolder          Contributor = "rightsholder"
	Supervisor            Contributor = "supervisor"
	WorkPackageLeader     Contributor = "workpackageleader"
	OtherContributor      Contributor = "other"
)

type Creator

type Creator struct {
	Name        string      `json:"name,omitzero"`        // Name of the creator in the format Family name, given names
	Type        Contributor `json:"type,omitzero"`        // Type of the contributor
	Affiliation string      `json:"affiliation,omitzero"` // Affiliation of the creator
	ORCID       string      `json:"orcid,omitzero"`       // ORCID identifier of creator
	GND         string      `json:"gnd,omitzero"`         // GND identifier of creator
}

type Custom

type Custom struct {
	CodeRepository       string                `json:"code:codeRepository,omitzero"`
	ProgrammingLanguages []ProgrammingLanguage `json:"code:programmingLanguage,omitzero"`
}

type Deposition

type Deposition struct {
	ID     int    `json:"id,omitzero"`      // Deposition identifier
	DOI    string `json:"doi,omitzero"`     // Digital Object Identifier
	DOIURL URL    `json:"doi_url,omitzero"` // Persistent link to the published deposition.
	Owner  int    `json:"owner,omitzero"`   // User identifier of the owner of the deposition.
	Title  string `json:"title,omitzero"`   // Title of deposition (automatically set from metadata).

	ConceptRecID string `json:"conceptrecid,omitzero"`
	ConceptDOI   string `json:"conceptdoi,omitzero"`

	RecordID int `json:"record_id,omitzero"` // Record identifier. Zero if the deposition is not published.

	// State of the deposition.
	// - "inprogress": Deposition metadata can be updated. If deposition is also unsubmitted
	//   files can be updated as well.
	// - "done": Deposition has been published.
	// - "error": Deposition is in an error state - contact Zenodo support.
	State string `json:"state,omitzero"`

	Submitted bool      `json:"submitted,omitzero"` // True if the deposition has been published, False otherwise
	Created   time.Time `json:"created,omitzero"`   // Creation time of deposition
	Modified  time.Time `json:"modified,omitzero"`  // Modification time of deposition

	Files []File `json:"files,omitzero"` // List of deposition files resources

	Links Links `json:"links,omitzero"`

	// Deposition metadata
	Metadata Metadata `json:"metadata,omitzero"`
}

type File

type File struct {
	ID       string  `json:"id"`
	Name     string  `json:"filename"`
	Size     float64 `json:"filesize"`
	Checksum string  `json:"checksum"`
	Links    struct {
		Self     URL `json:"self"`
		Download URL `json:"download"`
	} `json:"links"`
}

type Files

type Files struct {
	Enabled bool   `json:"enabled,omitzero"`
	Count   int    `json:"count,omitzero"`
	Entries []File `json:"entries,omitzero"`
}

type ImageType

type ImageType string
const (
	Figure         ImageType = "figure"
	Plot           ImageType = "plot"
	Drawing        ImageType = "drawing"
	Diagram        ImageType = "diagram"
	Photo          ImageType = "photo"
	OtherImageType ImageType = "other"
)
type Links struct {
	Self            URL `json:"self,omitzero"`
	HTML            URL `json:"html,omitzero"`
	DOI             URL `json:"doi,omitzero"`
	ParentDOI       URL `json:"parent_doi,omitzero"`
	Badge           URL `json:"badge,omitzero"`
	ConceptBadge    URL `json:"conceptbadge,omitzero"`
	Files           URL `json:"files,omitzero"`
	LatestDraft     URL `json:"latest_draft,omitzero"`
	LatestDraftHTML URL `json:"latest_draft_html,omitzero"`
	Publish         URL `json:"publish,omitzero"`
	Bucket          URL `json:"bucket,omitzero"`
	Edit            URL `json:"edit,omitzero"`
	Discard         URL `json:"discard,omitzero"`
	NewVersion      URL `json:"newversion,omitzero"`
	Record          URL `json:"record,omitzero"`
	RecordHTML      URL `json:"record_html,omitzero"`
	Latest          URL `json:"latest,omitzero"`
	LatestHTML      URL `json:"latest_html,omitzero"`
}

type Metadata

type Metadata struct {
	Title             string          `json:"title,omitzero"`
	DOI               string          `json:"doi,omitzero"`
	PublicationDate   string          `json:"publication_date,omitzero"`
	Description       string          `json:"description,omitzero"`
	AccessRight       AccessRight     `json:"access_right,omitzero"`
	Creators          []Creator       `json:"creators,omitzero"`
	RelatedIDs        []RelatedID     `json:"related_identifiers,omitzero"`
	Version           string          `json:"version,omitzero"`
	Custom            Custom          `json:"custom,omitzero"`
	License           string          `json:"license,omitzero"`
	JournalTitle      string          `json:"journal_title,omitzero"`
	JournalVolume     string          `json:"journal_volume,omitzero"`
	ConferenceAcronym string          `json:"conference_acronym,omitzero"`
	ImprintPublisher  string          `json:"imprint_publisher,omitzero"`
	UploadType        UploadType      `json:"upload_type,omitzero"`
	PublicationType   PublicationType `json:"publication_type,omitzero"`
	ImageType         ImageType       `json:"image_type,omitzero"`
	PreReserveDOI     PreReserveDOI   `json:"prereserve_doi,omitzero"`
}

type Option

type Option func(c *Client) error

Option configures how a Zenodo client should be created.

func WithHTTP

func WithHTTP(c *http.Client) Option

WithHTTP specifies an HTTP client to use with Zenodo requests.

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent modifies the default user agent for the Zenodo client.

type PreReserveDOI

type PreReserveDOI struct {
	DOI      string `json:"doi,omitzero"`
	RecordID int    `json:"recid,omitzero"`
}

type ProgrammingLanguage

type ProgrammingLanguage struct {
	ID    string `json:"id,omitzero"`
	Title struct {
		En string `json:"en,omitzero"`
	} `json:"title,omitzero"`
}

type PublicationType

type PublicationType string
const (
	AnnotationCollection  PublicationType = "annotationcollection"
	Book                  PublicationType = "book"
	Section               PublicationType = "section"
	ConferencePaper       PublicationType = "conferencepaper"
	DataManagementPlan    PublicationType = "datamanagementplan"
	Article               PublicationType = "article"
	Patent                PublicationType = "patent"
	PrePrint              PublicationType = "preprint"
	Deliverable           PublicationType = "deliverable"
	Mileston              PublicationType = "milestone"
	Proposal              PublicationType = "proposal"
	Report                PublicationType = "report"
	SoftwareDocumentation PublicationType = "softwaredocumentation"
	TaxonomicTreatment    PublicationType = "taxonomictreatment"
	TechnicalNote         PublicationType = "technicalnote"
	Thesis                PublicationType = "thesis"
	WorkingPaper          PublicationType = "workingpaper"
	OtherPublicationType  PublicationType = "other"
)

type RelatedID

type RelatedID struct {
	ID           URL    `json:"identifier,omitzero"`
	Relation     string `json:"relation,omitzero"`
	ResourceType string `json:"resource_type,omitzero"`
	Scheme       string `json:"scheme,omitzero"`
}

type URL

type URL string

type UploadType

type UploadType string
const (
	Publication     UploadType = "publication"
	Poster          UploadType = "poster"
	Presentation    UploadType = "presentation"
	Dataset         UploadType = "dataset"
	Image           UploadType = "image"
	Video           UploadType = "video"
	Software        UploadType = "software"
	Lesson          UploadType = "lesson"
	PhysicalObject  UploadType = "physicalobject"
	OtherUploadType UploadType = "other"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL