API service, library and parser for BBFC
Project description
BBFC API
Web API and Python library for BBFC.
Public REST API
- Hosted @ https://bbfcapi.fustra.co.uk
- Documentation @ https://bbfcapi.fustra.co.uk/redoc
- Alternative documentation @ https://bbfcapi.fustra.co.uk/docs
Try it now:
$ curl "https://bbfcapi.fustra.co.uk?title=interstellar&year=2014"
{"title":"INTERSTELLAR","year":2014,"ageRating":"12"}
Use the Python client:
$ pip install bbfcapi[apis]
>>> from bbfcapi.apis import top_search_result
>>> top_search_result("interstellar", 2014)
Film(title='INTERSTELLAR', year=2014, age_rating=<AgeRating.AGE_12: '12'>)
Project Overview
The project is divided into:
- "I want to self-host the REST API demoed above"
- BBFCAPI - Python REST Web API
pip install bbfcapi[app]
- "I want a Python library to talk to the REST API as demoed above"
- Python client for BBFCAPI
pip install bbfcapi[api]
(async variant)pip install bbfcapi[apis]
(sync variant)
- "I want a Python library to talk to the BBFC website"
- Python library for the BBFC website
pip install bbfcapi[lib]
(async variant)pip install bbfcapi[libs]
(sync variant)
- "I want to download the raw HTML web pages from BBFC"
- Python network client for the BBFC website
pip install bbfcapi[client]
(async variant)pip install bbfcapi[clients]
(sync variant)
- "I want to parse the downloaded web pages from BBFC"
- Python HMTL parser for the BBFC web pages
pip install bbfcapi
Sync versions use the requests
library, while async variants use aiohttp
.
High-Level REST Web API
Install pip install bbfcapi[app]
.
To use the REST API to query BBFC, first run the web server:
$ uvicorn bbfcapi.app:app
Then, to query the API using the Python library synchronously:
from bbfcapi.apis import top_search_result
top_search_result("interstellar", 2014, base_url="http://127.0.0.1:8000")
Or, to query the API using the Python library asynchronously:
from bbfcapi.api import top_search_result
print(await top_search_result("interstellar", 2014, base_url="http://127.0.0.1:8000"))
import asyncio
from bbfcapi.api import top_search_result
print(asyncio.run(top_search_result("interstellar", 2014, base_url="http://127.0.0.1:8000")))
Or, to query the API using curl
:
$ curl "127.0.0.1:8000?title=interstellar&year=2014"
{"title":"INTERSTELLAR","year":2014,"age_rating":"12"}
Or, to query the API from another web page:
async function call()
{
const response = await fetch('http://127.0.0.1:8000/?title=interstellar&year=2014');
const responseJson = await response.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 /docs folder.
High-Level Python Library
To use the library to get results from BBFC synchronously:
from bbfcapi.lib import top_search_result
print(top_search_result(title="interstellar", year=2014))
To use the library to get results from BBFC asynchronously:
from bbfcapi.lib import top_search_result
print(await top_search_result(title="interstellar", year=2014))
import asyncio
from bbfcapi.lib import top_search_result
print(asyncio.run(top_search_result(title="interstellar", year=2014)))
Low-Level BBFC Network Client & Parser
To use the library to get raw HTML pages from BBFC synchronously:
$ pip install bbfcapi[clients]`
from bbfcapi.clients import search
print(search(title="interstellar", year=2014))
To use the library to get raw HTML pages from BBFC asynchronously:
$ pip install bbfcapi[client]`
from bbfcapi.client import search
print(await search(title="interstellar", year=2014))
import asyncio
from bbfcapi.client import search
print(asyncio.run(search(title="interstellar", year=2014)))
To use the library to parse raw HTML pages from BBFC:
$ pip install bbfcapi`
from bbfcapi import parser
print(parser.parse_top_search_result(b"<BBFC search page byte-string>"))
Development
poetry install
to set up the virtualenv (one-off)poetry run uvicorn bbfcapi.apiweb:app --reload
to run the web servermake fix
,make check
, andmake test
before committing
There is also make test-live
which will run live integration tests against
the BBFC website.
Contributing
Pull requests are welcome :)
Publishing
This application is published on PyPi.
- Ensure you have configured the PyPi repository with Poetry (one-off)
- Run
make release
to execute the check-list
To publish to the test repository:
- Ensure you have configured the Test PyPi repository with Poetry (one-off)
poetry publish --build -r testpypi
to upload to the test repository
Changelog
v2.0.0.dev1
- Reorganise entire package
- Use camelCasing for JSON fields in the web API
v1.0.1 - 2020-01-19
- Fix parsing 12A age ratings
v1.0.0 - 2020-01-19
- First release of bbfcapi
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bbfcapi-2.0.0.dev1.tar.gz
.
File metadata
- Download URL: bbfcapi-2.0.0.dev1.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.5.9-arch1-2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 654807db9df1f8e7253613958a76672351e247e1ee436b2f0524e427f8e7a029 |
|
MD5 | 21deb8e9a6e97eeec67881946f5c9e11 |
|
BLAKE2b-256 | 22ab0c52e30abb938099aabc0cc53f07070c3c02550bff4383dcb8dd5a2d1984 |
File details
Details for the file bbfcapi-2.0.0.dev1-py3-none-any.whl
.
File metadata
- Download URL: bbfcapi-2.0.0.dev1-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.5.9-arch1-2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d10ad6b99a1f0fdea7798a51fbba25f354b7fc98a528cefd2174c27731fe25ae |
|
MD5 | 5ae8e99e316c7baeddf706676156e8cb |
|
BLAKE2b-256 | d67d1cbdc1725a7c350c5684ebd05ccc451d10b9348369144ef8ec9a817d7288 |