Skip to content

Pretalx

pretalx

Functionality around the Pretalx API

__all__ = ['PretalxClient', 'subs_as_df', 'speakers_as_df', 'reviews_as_df'] module-attribute

PretalxClient(config: Optional[Config] = None, blocking: bool = False)

Client for the Pretalx API

Source code in pytanis/pretalx/client.py
def __init__(self, config: Optional[Config] = None, blocking: bool = False):
    if config is None:
        config = get_cfg()
    self._config = config
    self._get_throttled = self._get
    self.blocking = blocking
    self.set_throttling(1, 2)  # we are nice by default

blocking = blocking instance-attribute

answer(event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Answer

Returns a specific answer

Source code in pytanis/pretalx/client.py
def answer(self, event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Answer:
    """Returns a specific answer"""
    return self._endpoint_id(Answer, event_slug, "answers", id, params=params)

answers(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Answer]]

Lists all answers and their details

Source code in pytanis/pretalx/client.py
def answers(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Answer]]:
    """Lists all answers and their details"""
    return self._endpoint_lst(Answer, event_slug, "answers", params=params)

event(event_slug: str, *, params: Optional[QueryParamType] = None) -> Event

Returns detailed information about a specific event

Source code in pytanis/pretalx/client.py
def event(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Event:
    """Returns detailed information about a specific event"""
    endpoint = f"/api/events/{event_slug}/"
    result = self._get_one(endpoint, params)
    _logger.debug("result", resp=result)
    return Event.parse_obj(result)

events(*, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Event]]

Lists all events and their details

Source code in pytanis/pretalx/client.py
def events(self, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Event]]:
    """Lists all events and their details"""
    count, results = self._get_many("/api/events/", params)
    events = iter(_logger.debug("result", resp=r) or Event.parse_obj(r) for r in results)
    return count, events

me() -> Me

Returns what Pretalx knows about myself

Source code in pytanis/pretalx/client.py
def me(self) -> Me:
    """Returns what Pretalx knows about myself"""
    result = self._get_one("/api/me")
    return Me.parse_obj(result)

question(event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Question

Returns a specific question

Source code in pytanis/pretalx/client.py
def question(self, event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Question:
    """Returns a specific question"""
    return self._endpoint_id(Question, event_slug, "questions", id, params=params)

questions(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Question]]

Lists all questions and their details

Source code in pytanis/pretalx/client.py
def questions(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Question]]:
    """Lists all questions and their details"""
    return self._endpoint_lst(Question, event_slug, "questions", params=params)

review(event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Review

Returns a specific review

Source code in pytanis/pretalx/client.py
def review(self, event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Review:
    """Returns a specific review"""
    return self._endpoint_id(Review, event_slug, "reviews", id, params=params)

reviews(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Review]]

Lists all reviews and their details

Source code in pytanis/pretalx/client.py
def reviews(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Review]]:
    """Lists all reviews and their details"""
    return self._endpoint_lst(Review, event_slug, "reviews", params=params)

room(event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Room

Returns a specific room

Source code in pytanis/pretalx/client.py
def room(self, event_slug: str, id: int, *, params: Optional[QueryParamType] = None) -> Room:
    """Returns a specific room"""
    return self._endpoint_id(Room, event_slug, "rooms", id, params=params)

rooms(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Room]]

Lists all rooms and their details

Source code in pytanis/pretalx/client.py
def rooms(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Room]]:
    """Lists all rooms and their details"""
    return self._endpoint_lst(Room, event_slug, "rooms", params=params)

set_throttling(calls: int, seconds: int)

Throttle the number of calls per seconds to the Pretalx API

Source code in pytanis/pretalx/client.py
def set_throttling(self, calls: int, seconds: int):
    """Throttle the number of calls per seconds to the Pretalx API"""
    _logger.info("throttling", calls=calls, seconds=seconds)
    self._get_throttled = throttle(calls, seconds)(self._get)

speaker(event_slug: str, code: str, *, params: Optional[QueryParamType] = None) -> Speaker

Returns a specific speaker

Source code in pytanis/pretalx/client.py
def speaker(self, event_slug: str, code: str, *, params: Optional[QueryParamType] = None) -> Speaker:
    """Returns a specific speaker"""
    return self._endpoint_id(Speaker, event_slug, "speakers", code, params=params)

speakers(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Speaker]]

Lists all speakers and their details

Source code in pytanis/pretalx/client.py
def speakers(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Speaker]]:
    """Lists all speakers and their details"""
    return self._endpoint_lst(Speaker, event_slug, "speakers", params=params)

submission(event_slug: str, code: str, *, params: Optional[QueryParamType] = None) -> Submission

Returns a specific submission

Source code in pytanis/pretalx/client.py
def submission(self, event_slug: str, code: str, *, params: Optional[QueryParamType] = None) -> Submission:
    """Returns a specific submission"""
    return self._endpoint_id(Submission, event_slug, "submissions", code, params=params)

submissions(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Submission]]

Lists all submissions and their details

Source code in pytanis/pretalx/client.py
def submissions(
    self, event_slug: str, *, params: Optional[QueryParamType] = None
) -> Tuple[int, Iterator[Submission]]:
    """Lists all submissions and their details"""
    return self._endpoint_lst(Submission, event_slug, "submissions", params=params)

tag(event_slug: str, tag: str, *, params: Optional[QueryParamType] = None) -> Tag

Returns a specific tag

Source code in pytanis/pretalx/client.py
def tag(self, event_slug: str, tag: str, *, params: Optional[QueryParamType] = None) -> Tag:
    """Returns a specific tag"""
    return self._endpoint_id(Tag, event_slug, "tags", tag, params=params)

tags(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Tag]]

Lists all tags and their details

Source code in pytanis/pretalx/client.py
def tags(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Tag]]:
    """Lists all tags and their details"""
    return self._endpoint_lst(Tag, event_slug, "tags", params=params)

talk(event_slug: str, code: str, *, params: Optional[QueryParamType] = None) -> Talk

Returns a specific talk

Source code in pytanis/pretalx/client.py
def talk(self, event_slug: str, code: str, *, params: Optional[QueryParamType] = None) -> Talk:
    """Returns a specific talk"""
    return self._endpoint_id(Talk, event_slug, "talks", code, params=params)

talks(event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Talk]]

Lists all talks and their details

Source code in pytanis/pretalx/client.py
def talks(self, event_slug: str, *, params: Optional[QueryParamType] = None) -> Tuple[int, Iterator[Talk]]:
    """Lists all talks and their details"""
    return self._endpoint_lst(Talk, event_slug, "talks", params=params)

reviews_as_df(reviews: Iterable[Review]) -> pd.DataFrame

Convert the reviews to a dataframe

Source code in pytanis/pretalx/utils.py
def reviews_as_df(reviews: Iterable[Review]) -> pd.DataFrame:
    """Convert the reviews to a dataframe"""
    df = pd.DataFrame([review.dict() for review in reviews])
    # make first letter of column upper-case in accordance with our convention
    df.rename(columns={col: col.title() for col in df.columns}, inplace=True)
    # user is the speaker name to use for joining
    df.rename(columns={"User": Col.pretalx_user, "Score": Col.review_score}, inplace=True)

    return df

speakers_as_df(speakers: Iterable[Speaker], with_questions: bool = False, question_prefix: str = 'Q: ') -> pd.DataFrame

Convert speakers into a dataframe

Make sure to have params={"questions": "all"} for the PretalxAPI if with_questions is True.

Source code in pytanis/pretalx/utils.py
def speakers_as_df(
    speakers: Iterable[Speaker], with_questions: bool = False, question_prefix: str = "Q: "
) -> pd.DataFrame:
    """Convert speakers into a dataframe

    Make sure to have `params={"questions": "all"}` for the PretalxAPI if `with_questions` is True.
    """
    rows = []
    for speaker in speakers:
        row = {
            Col.speaker_code: speaker.code,
            Col.speaker_name: speaker.name,
            Col.email: speaker.email,
            Col.biography: speaker.biography,
            Col.submission: speaker.submissions,
        }
        if with_questions and speaker.answers is not None:
            for answer in speaker.answers:
                # The API returns also questions that are 'per proposal/submission', we get these using the
                # submission endpoint and don't want them here due to ambiguity if several submission were made.
                if answer.person is not None:
                    row[f"{question_prefix}{answer.question.question.en}"] = answer.answer
        rows.append(row)
    return pd.DataFrame(rows)

subs_as_df(subs: Iterable[Submission], with_questions: bool = False, question_prefix: str = 'Q: ') -> pd.DataFrame

Convert submissions into a dataframe

Make sure to have params={"questions": "all"} for the PretalxAPI if with_questions is True.

Source code in pytanis/pretalx/utils.py
def subs_as_df(subs: Iterable[Submission], with_questions: bool = False, question_prefix: str = "Q: ") -> pd.DataFrame:
    """Convert submissions into a dataframe

    Make sure to have `params={"questions": "all"}` for the PretalxAPI if `with_questions` is True.
    """
    rows = []
    for sub in subs:
        row = {
            Col.submission: sub.code,
            Col.title: sub.title,
            Col.track: sub.track.en if sub.track else None,
            Col.speaker_code: [speaker.code for speaker in sub.speakers],
            Col.speaker_name: [speaker.name for speaker in sub.speakers],
            Col.duration: sub.duration,
            Col.submission_type: sub.submission_type.en,
            Col.submission_type_id: sub.submission_type_id,
            Col.state: sub.state.value,
            Col.pending_state: None if sub.pending_state is None else sub.pending_state.value,
            Col.created: sub.created,
        }
        if with_questions and sub.answers is not None:
            for answer in sub.answers:
                row[f"{question_prefix}{answer.question.question.en}"] = answer.answer
        rows.append(row)
    return pd.DataFrame(rows)