Package: bbfcapi
BBFC APIWeb API and Python library forBBFC.Public REST APIHosted @https://bbfcapi.fustra.ukDocumentation @https://bbfcapi.fustra.uk/redocAlternative documentation @https://bbfcapi.fustra.uk/docsTry it now:$curl"https://bbfcapi.fustra.uk?title=interstellar"{"title":"Interstellar","ageRating":"12"}Use the Python client:$pipinstallbbfcapi[api_sync]>>>frombbfcapi.api_syncimportbest_match>>>best_match("interstellar",2014)Film(title='INTERSTELLAR',age_rating=<AgeRating.AGE_12:'12'>)Project OverviewThe project is divided into:"I want to self-host the REST API demoed above"BBFCAPI - Python REST Web APIpip install bbfcapi[app]"I want a Python library to talk to the REST API as demoed above"Python client for BBFCAPIpip install bbfcapi[api_async](async variant)pip install bbfcapi[api_sync](sync variant)"I want a Python library to talk to the BBFC website"Python library for the BBFC websitepip install bbfcapi[lib_async](async variant)pip install bbfcapi[lib_sync](sync variant)"I want to download the raw HTML web pages from BBFC"Python network client for the BBFC websitepip install bbfcapi[client_async](async variant)pip install bbfcapi[client_sync](sync variant)"I want to parse the downloaded web pages from BBFC"Python HMTL parser for the BBFC web pagespip install bbfcapiSync versions use therequestslibrary, while async variants useaiohttp.High-Level REST Web APIInstallpip install bbfcapi[app].To use the REST API to query BBFC, first run the web server:$uvicornbbfcapi.app:appThen, to query the API using the Python librarysynchronously:frombbfcapi.api_syncimportbest_matchbest_match("interstellar",base_url="http://127.0.0.1:8000")Or, to query the API using the Python libraryasynchronously:frombbfcapi.api_asyncimportbest_matchprint(awaitbest_match("interstellar",base_url="http://127.0.0.1:8000"))importasynciofrombbfcapi.api_asyncimportbest_matchprint(asyncio.run(best_match("interstellar",base_url="http://127.0.0.1:8000")))Or, to query the API usingcurl:$curl"127.0.0.1:8000?title=interstellar"{"title":"Interstellar",age_rating":"12"}Or, to query the API from another web page:asyncfunctioncall(){constresponse=awaitfetch('http://127.0.0.1:8000/?title=interstellar');constresponseJson=awaitresponse.json();console.log(JSON.stringify(responseJson));}call();Additional notes:HTTP 404 Not Found is returned when there is no film found.Browse documentation @http://127.0.0.1:8000/redoc.Or, browse documentation @http://127.0.0.1:8000/docs.Samples on hosting this web application are available in the repository's/docsfolder.High-Level Python LibraryTo use the library to get results from BBFCsynchronously:frombbfcapi.lib_asyncimportbest_matchprint(best_match(title="interstellar"))To use the library to get results from BBFCasynchronously:frombbfcapi.lib_asyncimportbest_matchprint(awaitbest_match(title="interstellar"))importasynciofrombbfcapi.lib_asyncimportbest_matchprint(asyncio.run(best_match(title="interstellar")))Low-Level BBFC Network Client & ParserTo use the library to get raw HTML pages from BBFCsynchronously:$pipinstallbbfcapi[client_sync]`frombbfcapi.client_syncimportsearchprint(search(title="interstellar"))To use the library to get raw HTML pages from BBFCasynchronously:$pipinstallbbfcapi[client_async]`frombbfcapi.client_asyncimportsearchprint(awaitsearch(title="interstellar"))importasynciofrombbfcapi.client_asyncimportsearchprint(asyncio.run(search(title="interstellar")))To use the library to parse results from BBFC's GraphQL API:$pipinstallbbfcapi[parser]`frombbfcapiimportparserprint(parser.best_autocomplete_match({"BBFC":"...graphql json..."}))Developmentpoetry install -E allto set up the virtualenv (one-off)poetry run uvicorn bbfcapi.apiweb:app --reloadto run the web servermake fix,make check, andmake testbefore committingThere is alsomake test-livewhich will run live integration tests against
the BBFC website.ContributingPull requests are welcome :)PublishingThis application is published on PyPi.Ensure you have configured the PyPi repository with Poetry (one-off)Runmake releaseto execute the check-listTo publish to the test repository:Ensure you have configured the Test PyPi repository with Poetry (one-off)poetry publish --build -r testpypito upload to the test repositoryChangelogUnpublished...v3.0.1 - 2021-03-04Change primary host to bbfcapi.fustra.uk[Security] Upgrade dependenciesv3.0.0 - 2020-11-08IMPORTANT: Major changes for compatibility with BBFC's new websiteUpdate various dependenciesv2.0.2 - 2020-03-22Fix another missing dependencyv2.0.1 - 2020-03-22Fix missing dependenciesv2.0.0 - 2020-03-22Add Python client library for the BBFCAPI REST Web APIUse camelCasing for JSON fields in the web APIReorganise entire packagev1.0.1 - 2020-01-19Fix parsing 12A age ratingsv1.0.0 - 2020-01-19First release of bbfcapi