Skip to content

Commit 75515bf

Browse files
committed
improve readme
1 parent 05dd613 commit 75515bf

File tree

2 files changed

+26
-43
lines changed

2 files changed

+26
-43
lines changed

README.rst

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PDF generation in python using
1010
Wkhtmltopdf binaries are precompiled and included in the package making
1111
pydf easier to use, in particular this means pydf works on heroku.
1212

13-
Currently using **wkhtmltopdf 0.12.4 (with patched qt)**.
13+
Currently using **wkhtmltopdf 0.12.4 (with patched qt)**, requires **Python 3.6+**.
1414

1515
Install
1616
-------
@@ -19,7 +19,7 @@ Install
1919

2020
pip install python-pdf
2121

22-
(pydf was taken, but I guess python-pdf is a clearer name anyway.)
22+
For python 2 use ``pip install python-pdf==0.30.0``.
2323

2424
Basic Usage
2525
-----------
@@ -28,11 +28,7 @@ Basic Usage
2828
2929
import pydf
3030
pdf = pydf.generate_pdf('<h1>this is html</h1>')
31-
with open('test_doc.pdf', 'w') as f:
32-
f.write(pdf)
33-
34-
pdf = pydf.generate_pdf('www.google.com')
35-
with open('google.pdf', 'w') as f:
31+
with open('test_doc.pdf', 'wb') as f:
3632
f.write(pdf)
3733
3834
Async Usage
@@ -44,38 +40,28 @@ at the same time. Thus the time taken to spin up processes doesn't slow you down
4440

4541
.. code:: python
4642
47-
async def go_async():
48-
count = 20
49-
apydf = AsyncPydf(max_processes=20)
50-
51-
async def gen(i_):
52-
pdf = await apydf.generate_pdf(
53-
html,
54-
title='Benchmark',
55-
author='Samuel Colvin',
56-
subject='Mock Invoice',
57-
page_size='A4',
58-
zoom='1.25',
59-
margin_left='8mm',
60-
margin_right='8mm',
61-
)
62-
print(f'{i_:03}: {len(pdf)}')
63-
file = OUT_DIR / f'output_{i_:03}.pdf'
64-
file.write_bytes(pdf)
65-
66-
coros = []
67-
for i in range(count):
68-
coros.append(gen(i))
69-
await asyncio.gather(*coros)
70-
return count
71-
72-
loop = asyncio.get_event_loop()
73-
loop.run_until_complete(go_async())
43+
from pathlib import Path
44+
from pydf import AsyncPydf
45+
46+
async def generate_async():
47+
apydf = AsyncPydf()
48+
49+
async def gen(i):
50+
pdf_content = await apydf.generate_pdf('<h1>this is html</h1>')
51+
Path(f'output_{i:03}.pdf').write_bytes(pdf_content)
52+
53+
coros = [gen(i) for i in range(50)]
54+
await asyncio.gather(*coros)
55+
56+
loop = asyncio.get_event_loop()
57+
loop.run_until_complete(generate_async())
7458
7559
7660
See `benchmarks/run.py <https://github.com/tutorcruncher/pydf/blob/master/benchmark/run.py>`__
7761
for a full example.
7862

63+
Locally generating an entire invoice goes from 0.372s/pdf to 0.035s/pdf with the async model.
64+
7965
API
8066
---
8167

@@ -90,8 +76,7 @@ For details on extra arguments see the output of get\_help() and
9076
get\_extended\_help()
9177

9278
All arguments whether specified or caught with extra\_kwargs are
93-
converted to command line args with
94-
``'--' + original_name.replace('_', '-')``.
79+
converted to command line args with ``'--' + original_name.replace('_', '-')``.
9580

9681
Arguments which are True are passed with no value eg. just --quiet,
9782
False and None arguments are missed, everything else is passed with

benchmark/run.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def go_sync():
4040
print(f'sync, time taken per pdf: {time_taken:0.3f}s')
4141

4242
async def go_async():
43-
count = 20
44-
apydf = AsyncPydf(max_processes=20)
43+
apydf = AsyncPydf()
4544

4645
async def gen(i_):
4746
pdf = await apydf.generate_pdf(
@@ -55,12 +54,11 @@ async def gen(i_):
5554
margin_right='8mm',
5655
)
5756
print(f'{i_:03}: {len(pdf)}')
58-
file = OUT_DIR / f'output_{i_:03}.pdf'
59-
file.write_bytes(pdf)
57+
f = OUT_DIR / f'output_{i_:03}.pdf'
58+
f.write_bytes(pdf)
6059

61-
coros = []
62-
for i in range(count):
63-
coros.append(gen(i))
60+
count = 20
61+
coros = map(gen, range(count))
6462
await asyncio.gather(*coros)
6563
return count
6664

0 commit comments

Comments
 (0)