prismic Package¶
prismic
Package¶
Prismic.io python library.
api
Module¶
prismic.api¶
This module implements the Prismic API.
-
class
prismic.api.
Api
(data, access_token, cache, request_handler)¶ Bases:
object
A Prismic API, pointing to a specific repository. Use prismic.api.get() to fetch one.
Variables: - bookmarks (dict) – all bookmarks, as a dict from name to document id
- types (array<str>) – all available types
- tags (array<str>) – all available tags
- experiments (Experiments) – information about current experiments
- access_token (str) – current access token (may be None)
-
form
(name)¶ Constructs the form with data from Api. Returns
SearchForm
object.Parameters: name – Name of the form.
-
get_by_id
(id, ref=None)¶
-
get_by_ids
(ids, ref=None, page_size=None, page=None, orderings=None, after=None, fetch_links=None)¶
-
get_by_uid
(type, uid, ref=None)¶
-
get_ref
(label)¶ Get the
Ref
with a specific label. ReturnsRef
object.Parameters: label – Name of the label.
-
get_single
(type, ref=None)¶
-
preview_session
(token, link_resolver, default_url)¶ Return the URL to display a given preview
:param token as received from Prismic server to identify the content to preview :param link_resolver the link resolver to build URL for your site :param default_url the URL to default to return if the preview doesn’t correspond to a document
(usually the home page of your site)Returns: the URL to redirect the user to
-
query
(q, ref=None, page_size=None, page=None, orderings=None, after=None, fetch_links=None)¶
-
query_first
(q, ref=None)¶
-
class
prismic.api.
Document
(data)¶ Bases:
prismic.fragments.WithFragments
Represents a Prismic.io Document
Variables: - id (str) – document id
- uid (str) – document uid
- type (str) –
- href (str) –
- tags (array<str>) –
- slugs (array<str>) –
-
as_link
()¶ Convert the current document to a DocumentLink
Returns: DocumentLink
-
slug
¶ Return the most recent slug
Returns: str slug
-
class
prismic.api.
Ref
(data)¶ Bases:
object
A Prismic.io Reference (corresponds to a release)
-
class
prismic.api.
Response
(data)¶ Bases:
object
Prismic’s response to a query.
Variables: - documents (array<prismic.api.Document>) – the documents of the current page
- page (int) – the page in this result, starting by 1
- results_per_page (int) – max result in a page
- total_results_size (int) – total number of results for this query
- total_pages (int) – total number of pages for this query
- next_page (str) – URL of the next page (may be None if on the last page )
- prev_page (str) – URL of the previous page (may be None)
- results_size (int) – number of results actually returned for the current page
-
class
prismic.api.
SearchForm
(form, access_token, cache, request_handler)¶ Bases:
object
Form to search for documents. Most of the methods return self object to allow chaining.
-
after
(doc_id)¶ Start the result set after the given id
Parameters: doc_id – id of the reference document
-
count
()¶ Count the total number of results
-
fetch
(fields)¶ Restrict the results document to the specified fields
Parameters: fields – The list of fields, array or comma separated string
-
fetch_links
(fields)¶ Include the requested fields in the DocumentLink instances in the result
Parameters: fields – The list of fields, array or comma separated string
-
orderings
(orderings)¶ Sets the query orderings
:param orderings String with the orderings predicate :returns: the SearchForm instance to chain calls
-
page
(page_number)¶ Set query page number
Parameters: page_number – int representing the page number
-
pageSize
(nb_results)¶ Deprecated: use page_size instead
-
page_size
(nb_results)¶ Set query page size
Parameters: nb_results – int representing the number of results per page
-
query
(*argv)¶ Parameters: argv – Either a string query, or any number of Array corresponding to predicates. See the
prismic.predicates
module for helper functions.
-
set
(field, value)¶
-
submit_assert_preconditions
()¶
-
-
prismic.api.
get
(url, access_token=None, cache=None, request_handler=None)¶ Fetches the prismic api JSON. Returns
Api
object.Parameters: - url – URL to the api of the repository (mandatory).
- access_token – The access token (optional).
- cache – The cache object. Optional, will default to a file-based cache if None is passed.
- request_handler – The request handler. Optional, will default to a request handler based on requests module.
core
Module¶
exceptions
Module¶
prismic.exceptions¶
This module contains the set of Prismic exceptions.
-
exception
prismic.exceptions.
AuthorizationNeededError
¶ Bases:
prismic.exceptions.Error
You need to provide an access token to access this repository
-
exception
prismic.exceptions.
Error
¶ Bases:
exceptions.Exception
Base class for exceptions in this module.
-
exception
prismic.exceptions.
HTTPError
(code, message)¶ Bases:
prismic.exceptions.Error
HTTP error
-
exception
prismic.exceptions.
InvalidTokenError
¶ Bases:
prismic.exceptions.Error
The provided access token is either invalid or expired
-
exception
prismic.exceptions.
InvalidURLError
¶ Bases:
prismic.exceptions.Error
The prodider URL is invalid
-
exception
prismic.exceptions.
RefMissing
¶ Bases:
prismic.exceptions.Error
You need to provide the ref parameter.
-
exception
prismic.exceptions.
UnexpectedError
(message)¶ Bases:
prismic.exceptions.Error
Unexpected error.
fragments
Module¶
-
class
prismic.fragments.
Block
¶ Bases:
object
A block in a structured text
-
class
Block.
Heading
(value)¶ Bases:
prismic.fragments.Text
-
class
Block.
Image
(view)¶ Bases:
object
Block image
Parameters: view – The Fragment.Image.View object -
get_view
()¶
-
-
class
Block.
ListItem
(value, is_ordered=False)¶ Bases:
prismic.fragments.Text
-
class
Block.
Paragraph
(value)¶ Bases:
prismic.fragments.Text
-
class
-
class
prismic.fragments.
Fragment
¶ Bases:
object
-
class
BasicFragment
(value)¶
-
class
Fragment.
DocumentLink
(value)¶ Bases:
prismic.fragments.WithFragments
,prismic.fragments.Link
-
as_html
(documentlink_resolver, html_serializer=None)¶ Get the DocumentLink as html.
Parameters: documentlink_resolver – A resolver function will be called with prismic.fragments.Fragment.DocumentLink
object as argument. Resolver function should return a string, the local url to the document.
-
get_document_id
()¶
-
get_document_slug
()¶
-
get_document_type
()¶
-
get_url
(documentlink_resolver=None)¶
-
-
class
Fragment.
Embed
(value)¶ Bases:
prismic.fragments.FragmentElement
-
as_html
¶
-
-
class
Fragment.
FileLink
(value)¶ Bases:
prismic.fragments.Link
-
as_html
()¶
-
get_file
()¶
-
get_filename
()¶
-
get_url
(link_resolver=None)¶
-
-
class
Fragment.
GeoPoint
(value)¶ Bases:
prismic.fragments.FragmentElement
-
as_html
¶
-
-
class
Fragment.
Image
(value)¶ Bases:
prismic.fragments.FragmentElement
-
class
View
(data)¶ Bases:
prismic.fragments.FragmentElement
View class
-
as_html
(link_resolver)¶
-
ratio
¶
-
-
Fragment.Image.
as_html
(link_resolver)¶
-
Fragment.Image.
get_view
(key)¶
-
class
-
class
Fragment.
Link
¶ Bases:
prismic.fragments.FragmentElement
-
static
parse
(data)¶
-
static
-
class
Fragment.
MediaLink
(value)¶ Bases:
prismic.fragments.Link
-
as_html
()¶
-
get_url
(link_resolver=None)¶
-
-
class
Fragment.
Slice
(slice_type, slice_label, value)¶ Bases:
prismic.fragments.FragmentElement
-
as_html
(link_resolver)¶
-
-
class
Fragment.
SliceZone
(value)¶ Bases:
prismic.fragments.FragmentElement
-
as_html
(link_resolver)¶
-
-
class
Fragment.
WithFragments
(fragments)¶ Bases:
object
-
as_html
(link_resolver)¶
-
static
fragment_to_html
(fragment, link_resolver, html_serializer=None)¶
-
get
(field)¶
-
get_all
(field)¶
-
get_color
(field)¶
-
get_date
(field)¶
-
get_embed
(field)¶
-
get_field
(field)¶
-
get_fragment_type
(field, f_type)¶
-
get_geopoint
(field)¶
-
get_group
(field)¶
-
get_html
(field, link_resolver)¶ Get the html of a field.
Parameters: - field – String with a name of the field to get.
- link_resolver – A resolver function for document links.
Will be called with
prismic.fragments.Fragment.DocumentLink
object as argument. Resolver function should return a string, the local url to the document.
-
get_image
(field, view=u'main')¶
-
get_link
(field)¶
-
get_number
(field)¶
-
get_range
(field)¶
-
get_slice_zone
(field)¶
-
get_structured_text
(field)¶
-
get_text
(field)¶
-
get_timestamp
(field)¶
-
linked_documents
¶ Return the documents linked from this document’s fragments :return: array<DocumentLink>
-
-
classmethod
Fragment.
from_json
(data)¶ Create a corresponding fragment object from json.
-
class
-
class
prismic.fragments.
FragmentElement
¶ Bases:
object
-
class
prismic.fragments.
Span
¶ Bases:
object
-
class
Em
(value)¶ Bases:
prismic.fragments.SpanElement
-
class
Span.
Strong
(value)¶ Bases:
prismic.fragments.SpanElement
-
classmethod
Span.
from_json
(data)¶
-
class
-
class
prismic.fragments.
StructuredText
(values)¶ Bases:
object
-
class
Group
(tag, blocks)¶ Bases:
object
-
StructuredText.
as_html
(link_resolver, html_serializer=None)¶
-
static
StructuredText.
block_as_html
(block, content, link_resolver, html_serializer)¶
-
StructuredText.
get_first_paragraph
()¶
-
StructuredText.
get_image
()¶
-
StructuredText.
get_title
()¶
-
static
StructuredText.
span_as_html
(text, spans, link_resolver, html_serializer)¶
-
static
StructuredText.
span_write_tag
(span, content, link_resolver, html_serializer)¶
-
class
-
class
prismic.fragments.
Text
(value)¶ Bases:
object
Base class for blocks