@@ -35,12 +35,14 @@ Complete API documentation is available on `Read the Docs
3535Usage
3636-----
3737
38- To use this API, create a new ``minfraud.Client `` object. The constructor
39- takes your MaxMind account ID and license key:
38+ To use this API, create a new ``minfraud.Client `` object for a synchronous
39+ request or ``minfraud.AsyncClient `` for an asynchronous request. The
40+ constructors take your MaxMind account ID and license key:
4041
4142.. code-block :: pycon
4243
4344 >>> client = Client(42, 'licensekey')
45+ >>> async_client = AsyncClient(42, 'licensekey')
4446
4547 Score, Insights and Factors Usage
4648^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,19 +51,22 @@ The Factors service is called with the ``factors()`` method:
4951
5052.. code-block :: pycon
5153
52- >>> factors = client.factors({'device': {'ip_address': '81.2.69.160'}})
54+ >>> client.factors({'device': {'ip_address': '81.2.69.160'}})
55+ >>> await async_client.factors({'device': {'ip_address': '81.2.69.160'}})
5356
5457 The Insights service is called with the ``insights() `` method:
5558
5659.. code-block :: pycon
5760
58- >>> insights = client.insights({'device': {'ip_address': '81.2.69.160'}})
61+ >>> client.insights({'device': {'ip_address': '81.2.69.160'}})
62+ >>> await async_client.insights({'device': {'ip_address': '81.2.69.160'}})
5963
6064 The Score web service is called with the ``score() `` method:
6165
6266.. code-block :: pycon
6367
64- >>> score = client.score({'device': {'ip_address': '81.2.69.160'}})
68+ >>> client.score({'device': {'ip_address': '81.2.69.160'}})
69+ >>> await async_client.score({'device': {'ip_address': '81.2.69.160'}})
6570
6671 Each of these methods takes a dictionary representing the transaction to be sent
6772to the web service. The structure of this dictionary should be in `the format
@@ -80,6 +85,7 @@ Report Transaction web service is called with the ``report()`` method:
8085.. code-block :: pycon
8186
8287 >>> client.report({'ip_address': '81.2.69.160', 'tag': 'chargeback'})
88+ >>> await async_client.report({'ip_address': '81.2.69.160', 'tag': 'chargeback'})
8389
8490 The method takes a dictionary representing the report to be sent to the web
8591service. The structure of this dictionary should be in `the format specified
@@ -130,9 +136,8 @@ Score, Insights and Factors Example
130136
131137.. code-block :: pycon
132138
133- >>> from minfraud import Client
134- >>>
135- >>> client = Client(42, 'licensekey')
139+ >>> import asyncio
140+ >>> from minfraud import AsyncClient, Client
136141 >>>
137142 >>> request = {
138143 >>> 'device': {
@@ -224,30 +229,69 @@ Score, Insights and Factors Example
224229 >>> }
225230 >>> }
226231 >>>
227- >>> client.score(request)
232+ >>> # This example function uses a synchronous Client object. The object
233+ >>> # can be used across multiple requests.
234+ >>> def client(account_id, license_key):
235+ >>> with Client(account_id, license_key) as client:
236+ >>>
237+ >>> print(client.score(request))
238+ Score(...)
239+ >>>
240+ >>> print(client.insights(request))
241+ Insights(...)
242+ >>>
243+ >>> print(client.factors(request))
244+ Factors(...)
245+ >>>
246+ >>> # This example function uses an asynchronous AsyncClient object. The
247+ >>> # object can be used across multiple requests.
248+ >>> async def async_client(account_id, license_key):
249+ >>> with Client(account_id, license_key) as client:
250+ >>>
251+ >>> print(client.score(request))
228252 Score(...)
229253 >>>
230- >>> client.insights(request)
254+ >>> print( client.insights(request) )
231255 Insights(...)
232256 >>>
233- >>> client.factors(request)
257+ >>> print( client.factors(request) )
234258 Factors(...)
259+ >>>
260+ >>> client(42, 'license_key')
261+ >>> asyncio.run(async_client(42, 'license_key'))
235262
236263 Report Transactions Example
237264^^^^^^^^^^^^^^^^^^^^^^^^^^^
238265
239- .. code-block :: pycon
266+ For synchronous reporting:
240267
268+ .. code-block :: pycon
241269 >>> from minfraud import Client
242270 >>>
243- >>> client = Client(42, 'licensekey')
271+ >>> with Client(42, 'licensekey') as client
272+ >>> transaction_report = {
273+ >>> 'ip_address': '81.2.69.160',
274+ >>> 'tag': 'chargeback',
275+ >>> 'minfraud_id': '2c69df73-01c0-45a5-b218-ed85f40b17aa',
276+ >>> }
277+ >>> client.report(transaction_report)
278+
279+ For asynchronous reporting:
280+
281+ .. code-block :: pycon
282+ >>> import asyncio
283+ >>> from minfraud import AsyncClient
244284 >>>
245- >>> transaction_report = {
246- >>> 'ip_address': '81.2.69.160',
247- >>> 'tag': 'chargeback',
248- >>> 'minfraud_id': '2c69df73-01c0-45a5-b218-ed85f40b17aa',
249- >>> }
250- >>> client.report(transaction_report)
285+ >>> async def report():
286+ >>> async with AsyncClient(42, 'licensekey') as client
287+ >>> transaction_report = {
288+ >>> 'ip_address': '81.2.69.160',
289+ >>> 'tag': 'chargeback',
290+ >>> 'minfraud_id': '2c69df73-01c0-45a5-b218-ed85f40b17aa',
291+ >>> }
292+ >>> await async_client.report(transaction_report)
293+ >>>
294+ >>> asyncio.run(report())
251295
252296 Requirements
253297------------
0 commit comments