Skip to main content

Documentation Status

S4Gpy a python client library for Stream-for-Good Project

This client api can be used to perform analysis of S4G dataset with Python3.

It closely mirros the HATEAOS from the Rest API so that when requesting data, the links information are automatically converted to functions that can be called from the API.

For example with the user API

you can get a Python version with the following syntax:

from s4gpy.s4gpy import S4GAPI
#first register with your vod-prime.space credentials
api=S4GAPI()
#then get a user API object
user_api=api.get_user_api()

#get the users from the API
for u in user_api.get_users():
    #for each user, follow the all-thumbnails link by calling the all_thumbnails() function.
    for t in u.all_thumbnails()["thumbnails"]:
        print(f"{u.user.user_id};{t.row};{t.col};{t.video_id};{t.timestamp}")

this code prints out the users' id, and some metadata on thumbnails that were proposed to her.

1f52213c-f31d-4dc9-bac5-35464b2ff1b9;4;1;81074110;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;4;0;80994082;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;6;0;81277950;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;5;2;80232398;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;5;3;80234304;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;4;3;80095697;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;5;0;80025678;1610984584.0

Installation

From Pypi

pip install s4gpy

From source

#uninstall first
pip uninstall s4gpy
make build
pip install dist/*.whl

Examples

Direct API

Get the current direct schedule, with metadata from the companion platform-api

from s4gpy.s4gpy import S4GAPI
api=S4GAPI()
for s in api.get_direct_api().get_direct_schedule():
    try:
        imdb_data=s.content().imdb_id()
        genres="+".join([g["genre"] for g in imdb_data.data.genres])
    except AttributeError: #in case platform.vod-prime.space fucks up things
        print(f"{s.airing_time};{s.video_id};UNKNOWN;UNKNOWN")
        continue
    print(f"{s.airing_time};{s.video_id};{imdb_data.data.title};f{genres}")

User API

Show the row/cols of every watched video for each user

from s4gpy.s4gpy import S4GAPI
#create an API entrypoint
api=S4GAPI()
#get the user_api
user_api=api.get_user_api()

#for each user
for u in user_api.get_users():
    #get all the video she watched
    watched_videos=[w.video_id for w in u.all_watches().watches]
    #for all the thumbnails
    for t in u.all_thumbnails()["thumbnails"]:
        #only dump the informations if the user has wached the video
        if t.video_id in watched_videos:
            print(f"{u.user.user_id};{t.row};{t.col};{t.video_id};{t.timestamp}")

Direct API

Get the current direct schedule, with metadata from the companion platform-api

from s4gpy.s4gpy import S4GAPI
api=S4GAPI()
for s in api.get_direct_api().get_direct_schedule():
    try:
        imdb_data=s.content().imdb_id()
        genres="+".join([g["genre"] for g in imdb_data.data.genres])
    except AttributeError: #in case platform.vod-prime.space fucks up things
        print(f"{s.airing_time};{s.video_id};UNKNOWN;UNKNOWN")
        continue
    print(f"{s.airing_time};{s.video_id};{imdb_data.data.title};f{genres}")

Credential API

Get some credentials for netflix to run a robot run

from s4gpy.s4gpy import S4GAPI
api=S4GAPI()
login, password = api.get_credentials_api().get_credentials("netflix")

Company Mapping API

Get/Set the mappings for content and company

from s4gpy.s4gpy import S4GAPI
from s4gpy.api.companyapi import CompanyAPI
from s4gpy.s4gsession import S4GSession
api = S4GAPI()

api.get_company_api().push_company("company1_cc_code",name="company 1 name",link="company 1 link")
api.get_company_api().push_company("company2_cc_code",name="company 2 name",link="company 2 link")
api.get_company_api().push_content("content_code",["company 1 name","company 2 name"])

for company in api.get_company_api().get_companies():
    print(f"company code {company.company_id} is {company.company().name}")
for content in api.get_company_api().get_contents():
    for company in content.content().companies():
        print(f"content {content.content_id} is produced by {company.company_id}")

Metadata

Release files for s4gpy 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for s4gpy 0.1.0
File Interpreter ABI Platform
s4gpy-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / s4gpy-0.1.0-py2.py3-none-any.whl

Download URL s4gpy-0.1.0-py2.py3-none-any.whl
Size 10.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a2a4308b15641de1feb02d807bd5589e201850f3e2e259153e99b4089202188f
BLAKE2b-256 checksum
How to use checksums
ae869338b1cadf7e67b6ac0ac86d0649184b8a9739dcff58420bb5ce12fc0694
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/61.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page