API¶
You can build you own tests, validators and sanitizers using these classes.
-
class
pyscrawl.Scrawl(api_key, server='https://scrawl.nl')[source]¶ Scrawl API service.
This allows you to call our API service with ease.
Parameters: - api_key (str) – Your Scrawl API key.
- server (str) – The Scrawl server location.
from pyscrawl import Scrawl scrawl = Scrawl('my-api-key')
-
upload_zipfile(title, filename, override=False)[source]¶ Upload a new document to scrawl.
Parameters: - title (str) – The title of the document.
- filename (str) – Name of the zip-file to upload.
- override (bool) – Override if document with the same name exists. Defaults to False.
Return type: result = scrawl.upload_zipfile('PyScrawl test', './document.zip') result.sleep_until_ready()
-
upload_container(title, container, override=False)[source]¶ Upload a new document to scrawl using ScrawlContainer.
You can use this to construct a zip-file on the fly.
Parameters: - title (str) – The title of the document.
- container (ScrawlContainer) – The container to upload.
- override (bool) – Override if document with the same name exists. Defaults to False.
Return type:
-
upload_stream(title, stream, override=False)[source]¶ Upload a new document using a BytesIO stream.
We recommand you use
upload_zipfile()orupload_container(), but you can use this when you want to do something more advanced.Parameters: - title (str) – The title of the document.
- stream (_IOBase) – The stream to upload.
- override (bool) – Override if document with the same name exists. Defaults to False.
Return type:
-
class
pyscrawl.ScrawlContainer[source]¶ Scrawl Container (in-memory ZipFile).
This allows you to programmaticaly build a ZipFile in memory. Use
add_file()andadd_content()to build the ZipFile. When you are done, you can upload it by callingScrawl.upload_container().Parameters: api_key (str) – Your Scrawl API key. from pyscrawl import Scrawl, ScrawlContainer scrawl = Scrawl('my-api-key') # define an index_html using a template engine (for example) index_html = '''<html>...</html>''' # build a new document container = (ScrawlContainer() .add_file('./styles.css') .add_file('./awesome-logo.png') .add_content('index.html', index_html)) # upload to Scrawl and wait for the conversion. result = scrawl.upload_container('PyScrawl test', container) result.sleep_until_ready()
-
add_file(filename)[source]¶ Add a file from disk to the container.
Parameters: filename (str) – The filename on the disk. Return type: ScrawlContainer
-
add_content(filename, content)[source]¶ Add content to the container.
Parameters: - filename (str) – How to represent the content.
- content (str) – The actual content
Return type:
-
get_stream()[source]¶ Build a BytesIO in-memory ZipFile based on the files.
Use
add_file()andadd_content()to prepare the container. When done, you can callget_stream()to build a in-memory ZipFile based on the current configuration.When using
Scrawl.upload_container(), this method is automaticly called.Return type: BytesIO
-
-
class
pyscrawl.ScrawlResultDocument(result, api_key)[source]¶ Scrawl Result Document.
When calling the API, this result document is returned. It contains information about your uploaded document.
See
Scrawl.upload_zipfile()orScrawl.upload_container()for more information.Variables: - api_key (str) – The API key.
- info (str) – Information URL.
- pdf (str) – URL, for downloading or viewing the PDF.
- html (str) – URL, for online viewing the uploaded HTML document.
- converted (bool) – True when Scrawl has converted the document to PDF.
- placed_on (datetime.datetime) – DateTime when the document was added to the Scrawler convertion queue.
- processed_on (datetime.datetime) – DateTime when the document was processed by the Scrawler (converted is True, when this is set).
-
sleep_until_ready(delay=1)[source]¶ Sleep (in delays) until Scrawl has converted the document.
Until the
convertedbit is set to True. You can always store thepdflink, even if the conversion has not yet been completed.Parameters: delay (int) – The amount of seconds to sleep (at least 1 second). Return type: bool