Copyright | Copyright (C) 2019 John MacFarlane |
---|---|
License | BSD3 |
Maintainer | John MacFarlane <jgm@berkeley.edu> |
Stability | alpha |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Data.Ipynb
Description
Data structure and JSON serializers for ipynb (Jupyter notebook) format. Version 4 of the format is documented here: https://nbformat.readthedocs.io/en/latest/format_description.html.
The library supports both version 4 ('Notebook NbV4') and version 3
('Notebook NbV3') of nbformat. Note that this is a phantom type: the
NbV3
or NbV4
parameter only affects JSON serialization,
not the data structure itself. So code that manipulates
notebooks can be polymorphic, operating on `Notebook a`.
Synopsis
- data Notebook a = Notebook {
- notebookMetadata :: JSONMeta
- notebookFormat :: (Int, Int)
- notebookCells :: [Cell a]
- data NbV3
- data NbV4
- newtype JSONMeta = JSONMeta (Map Text Value)
- data Cell a = Cell {}
- newtype Source = Source {}
- data CellType a
- = Markdown
- | Heading {
- headingLevel :: Int
- | Raw
- | Code {
- codeExecutionCount :: Maybe Int
- codeOutputs :: [Output a]
- data Output a
- = Stream {
- streamName :: Text
- streamText :: Source
- | DisplayData { }
- | ExecuteResult { }
- | Err { }
- = Stream {
- type MimeType = Text
- data MimeData
- newtype MimeBundle = MimeBundle {}
- newtype MimeAttachments = MimeAttachments (Map Text MimeBundle)
- breakLines :: Text -> [Text]
Documentation
A Jupyter notebook.
Constructors
Notebook | |
Fields
|
Instances
Indexes Notebook
for serialization as nbformat version 3.
Indexes Notebook
for serialization as nbformat version 4.
A Jupyter notebook cell.
Constructors
Cell | |
Fields
|
Instances
FromJSON (Cell NbV3) # | |||||
FromJSON (Cell NbV4) # | |||||
ToJSON (Cell NbV3) # | |||||
ToJSON (Cell NbV4) # | |||||
Generic (Cell a) # | |||||
Defined in Data.Ipynb Associated Types
| |||||
Show (Cell a) # | |||||
Eq (Cell a) # | |||||
type Rep (Cell a) # | |||||
Defined in Data.Ipynb type Rep (Cell a) = D1 ('MetaData "Cell" "Data.Ipynb" "ipynb-0.2-ECEsTZjwSEXDGeec6C4GR9" 'False) (C1 ('MetaCons "Cell" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cellType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (CellType a)) :*: S1 ('MetaSel ('Just "cellId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))) :*: (S1 ('MetaSel ('Just "cellSource") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Source) :*: (S1 ('MetaSel ('Just "cellMetadata") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 JSONMeta) :*: S1 ('MetaSel ('Just "cellAttachments") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe MimeAttachments)))))) |
A Source
is a textual content which may be
represented in JSON either as a single string
or as a list of strings (which are concatenated).
Information about the type of a notebook cell, plus
data specific to that type. note that Heading
is
for v3 only; a Heading
will be rendered as Markdown
in v4.
Constructors
Markdown | |
Heading | |
Fields
| |
Raw | |
Code | |
Fields
|
Instances
Generic (CellType a) # | |||||
Defined in Data.Ipynb Associated Types
| |||||
Show (CellType a) # | |||||
Eq (CellType a) # | |||||
type Rep (CellType a) # | |||||
Defined in Data.Ipynb type Rep (CellType a) = D1 ('MetaData "CellType" "Data.Ipynb" "ipynb-0.2-ECEsTZjwSEXDGeec6C4GR9" 'False) ((C1 ('MetaCons "Markdown" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Heading" 'PrefixI 'True) (S1 ('MetaSel ('Just "headingLevel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))) :+: (C1 ('MetaCons "Raw" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Code" 'PrefixI 'True) (S1 ('MetaSel ('Just "codeExecutionCount") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int)) :*: S1 ('MetaSel ('Just "codeOutputs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Output a])))) |
Output from a Code cell.
Constructors
Stream | |
Fields
| |
DisplayData | |
Fields | |
ExecuteResult | |
Fields | |
Err | |
Instances
FromJSON (Output NbV3) # | |||||
FromJSON (Output NbV4) # | |||||
ToJSON (Output NbV3) # | |||||
ToJSON (Output NbV4) # | |||||
Generic (Output a) # | |||||
Defined in Data.Ipynb Associated Types
| |||||
Show (Output a) # | |||||
Eq (Output a) # | |||||
type Rep (Output a) # | |||||
Defined in Data.Ipynb type Rep (Output a) = D1 ('MetaData "Output" "Data.Ipynb" "ipynb-0.2-ECEsTZjwSEXDGeec6C4GR9" 'False) ((C1 ('MetaCons "Stream" 'PrefixI 'True) (S1 ('MetaSel ('Just "streamName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "streamText") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Source)) :+: C1 ('MetaCons "DisplayData" 'PrefixI 'True) (S1 ('MetaSel ('Just "displayData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MimeBundle) :*: S1 ('MetaSel ('Just "displayMetadata") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 JSONMeta))) :+: (C1 ('MetaCons "ExecuteResult" 'PrefixI 'True) (S1 ('MetaSel ('Just "executeCount") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: (S1 ('MetaSel ('Just "executeData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MimeBundle) :*: S1 ('MetaSel ('Just "executeMetadata") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 JSONMeta))) :+: C1 ('MetaCons "Err" 'PrefixI 'True) (S1 ('MetaSel ('Just "errName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "errValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "errTraceback") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]))))) |
Data in an execution result or display data cell.
Constructors
BinaryData ByteString | |
TextualData Text | |
JsonData Value |
Instances
ToJSON MimeData # | |||||
Generic MimeData # | |||||
Defined in Data.Ipynb Associated Types
| |||||
Show MimeData # | |||||
Eq MimeData # | |||||
Ord MimeData # | |||||
Defined in Data.Ipynb | |||||
type Rep MimeData # | |||||
Defined in Data.Ipynb type Rep MimeData = D1 ('MetaData "MimeData" "Data.Ipynb" "ipynb-0.2-ECEsTZjwSEXDGeec6C4GR9" 'False) (C1 ('MetaCons "BinaryData" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)) :+: (C1 ('MetaCons "TextualData" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: C1 ('MetaCons "JsonData" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)))) |
newtype MimeBundle #
A MimeBundle
wraps a map from mime types to mime data.
Constructors
MimeBundle | |
Fields |
Instances
FromJSON MimeBundle # | |||||
Defined in Data.Ipynb | |||||
ToJSON MimeBundle # | |||||
Defined in Data.Ipynb Methods toJSON :: MimeBundle -> Value # toEncoding :: MimeBundle -> Encoding # toJSONList :: [MimeBundle] -> Value # toEncodingList :: [MimeBundle] -> Encoding # omitField :: MimeBundle -> Bool # | |||||
Monoid MimeBundle # | |||||
Defined in Data.Ipynb Methods mempty :: MimeBundle # mappend :: MimeBundle -> MimeBundle -> MimeBundle # mconcat :: [MimeBundle] -> MimeBundle # | |||||
Semigroup MimeBundle # | |||||
Defined in Data.Ipynb Methods (<>) :: MimeBundle -> MimeBundle -> MimeBundle # sconcat :: NonEmpty MimeBundle -> MimeBundle # stimes :: Integral b => b -> MimeBundle -> MimeBundle # | |||||
Generic MimeBundle # | |||||
Defined in Data.Ipynb Associated Types
| |||||
Show MimeBundle # | |||||
Defined in Data.Ipynb Methods showsPrec :: Int -> MimeBundle -> ShowS # show :: MimeBundle -> String # showList :: [MimeBundle] -> ShowS # | |||||
Eq MimeBundle # | |||||
Defined in Data.Ipynb | |||||
Ord MimeBundle # | |||||
Defined in Data.Ipynb Methods compare :: MimeBundle -> MimeBundle -> Ordering # (<) :: MimeBundle -> MimeBundle -> Bool # (<=) :: MimeBundle -> MimeBundle -> Bool # (>) :: MimeBundle -> MimeBundle -> Bool # (>=) :: MimeBundle -> MimeBundle -> Bool # max :: MimeBundle -> MimeBundle -> MimeBundle # min :: MimeBundle -> MimeBundle -> MimeBundle # | |||||
type Rep MimeBundle # | |||||
Defined in Data.Ipynb type Rep MimeBundle = D1 ('MetaData "MimeBundle" "Data.Ipynb" "ipynb-0.2-ECEsTZjwSEXDGeec6C4GR9" 'True) (C1 ('MetaCons "MimeBundle" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMimeBundle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map MimeType MimeData)))) |
newtype MimeAttachments #
Constructors
MimeAttachments (Map Text MimeBundle) |
Instances
FromJSON MimeAttachments # | |||||
Defined in Data.Ipynb Methods parseJSON :: Value -> Parser MimeAttachments # parseJSONList :: Value -> Parser [MimeAttachments] # | |||||
ToJSON MimeAttachments # | |||||
Defined in Data.Ipynb Methods toJSON :: MimeAttachments -> Value # toEncoding :: MimeAttachments -> Encoding # toJSONList :: [MimeAttachments] -> Value # toEncodingList :: [MimeAttachments] -> Encoding # omitField :: MimeAttachments -> Bool # | |||||
Monoid MimeAttachments # | |||||
Defined in Data.Ipynb Methods mappend :: MimeAttachments -> MimeAttachments -> MimeAttachments # mconcat :: [MimeAttachments] -> MimeAttachments # | |||||
Semigroup MimeAttachments # | |||||
Defined in Data.Ipynb Methods (<>) :: MimeAttachments -> MimeAttachments -> MimeAttachments # sconcat :: NonEmpty MimeAttachments -> MimeAttachments # stimes :: Integral b => b -> MimeAttachments -> MimeAttachments # | |||||
Generic MimeAttachments # | |||||
Defined in Data.Ipynb Associated Types
Methods from :: MimeAttachments -> Rep MimeAttachments x # to :: Rep MimeAttachments x -> MimeAttachments # | |||||
Show MimeAttachments # | |||||
Defined in Data.Ipynb Methods showsPrec :: Int -> MimeAttachments -> ShowS # show :: MimeAttachments -> String # showList :: [MimeAttachments] -> ShowS # | |||||
Eq MimeAttachments # | |||||
Defined in Data.Ipynb Methods (==) :: MimeAttachments -> MimeAttachments -> Bool # (/=) :: MimeAttachments -> MimeAttachments -> Bool # | |||||
Ord MimeAttachments # | |||||
Defined in Data.Ipynb Methods compare :: MimeAttachments -> MimeAttachments -> Ordering # (<) :: MimeAttachments -> MimeAttachments -> Bool # (<=) :: MimeAttachments -> MimeAttachments -> Bool # (>) :: MimeAttachments -> MimeAttachments -> Bool # (>=) :: MimeAttachments -> MimeAttachments -> Bool # max :: MimeAttachments -> MimeAttachments -> MimeAttachments # min :: MimeAttachments -> MimeAttachments -> MimeAttachments # | |||||
type Rep MimeAttachments # | |||||
Defined in Data.Ipynb type Rep MimeAttachments = D1 ('MetaData "MimeAttachments" "Data.Ipynb" "ipynb-0.2-ECEsTZjwSEXDGeec6C4GR9" 'True) (C1 ('MetaCons "MimeAttachments" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Text MimeBundle)))) |
breakLines :: Text -> [Text] #
Break up a string into a list of strings, each representing one line of the string (including trailing newline if any).