Skip to main content

Interact with CoWin APIs

Project description

Cowin API

Python package to interact with COWIN Public API

Features

  • Supports both Synchronous and Asynchronous modes.
  • 95% test coverage with mocking API responses.
  • Get list of states
  • Get list of districts for a state
  • Get vaccine centers with sessions by pincode and date
  • Generate and Verify OTP
  • Download Certificates

Example:

For API response payload samples visit the API portal.

# blocking synchronous client
from cowin import Cowin

client = Cowin()

states = client.get_states()
districts = client.get_districts(state_id=4)

# below function accepts optional datetime.date object
# by default current date is used
vaccine_sessions = client.get_available_sessions_by_pincode(pincode=605001)

# get OTP to mobile number
response = client.get_otp(mobile='9876543210')
txn_id = response['txnId']

# verify OTP and receive token
response = client.confirm_otp(txn_id=txn_id, otp=123456)
token = response['token']

# download certificate by beneficiary reference number
# Note: ServerError exception will be raised when response content is not pdf
cert_content = client.get_certificate(token, beneficiary_id='xxxxxxxxxxxx')

# save certificate content to disk
with open('certificate.pdf', 'wb') as cert_file:
    cert_file.write(cert_content)
# non-blocking async client
from cowin import AsyncCowin

async_client = AsyncCowin()

states = await async_client.get_stateS()
districts = await async_client.get_districts(state_id=4)

vaccine_sessions = await async_client.get_available_sessions_by_pincode(pincode='605001')

# get OTP to mobile number
response = await async_client.get_otp(mobile='9876543210')
txn_id = response['txnId']

# verify OTP and receive token
response = await async_client.confirm_otp(txn_id=txn_id, otp='123456')
token = response['token']

# download certificate by beneficiary reference number
# Note: ServerError exception will be raised when response content is not pdf
cert_content = await async_client.get_certificate(token, beneficiary_id='xxxxxxxxxxxx')

# save certificate content to disk
with open('certificate.pdf', 'wb') as cert_file:
    cert_file.write(cert_content)

Contributions

Issues and pull requests are welcome. Feel free to improve the package.

License:

LGPL v3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cowin-async-1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cowin_async-1.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file cowin-async-1.1.tar.gz.

File metadata

  • Download URL: cowin-async-1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5

File hashes

Hashes for cowin-async-1.1.tar.gz
Algorithm Hash digest
SHA256 09844bb425baf37436598cebba13fc8d4ab662938ea4d06a823bbdfe4a9e90a6
MD5 cd9dd24011ea1a432567026fb777739e
BLAKE2b-256 6a2ac27f3beee42b8e2473dd37bb1a1aa121fe9719269372c2e9ed9c0e9adc3d

See more details on using hashes here.

File details

Details for the file cowin_async-1.1-py3-none-any.whl.

File metadata

  • Download URL: cowin_async-1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5

File hashes

Hashes for cowin_async-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d7172bd0cb69676094d7d88181640fdc139ccab1dda648232fc95ff34a180e0
MD5 df87912f19b469a6ce3753eed546f1be
BLAKE2b-256 447c2e2fc23e9be21b4c4188fd988d9579eadada76f80d236a48a0570b6b08a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page