Skip to main content

Python SDK for the AccessGrid API

Project description

AccessGrid SDK

A Python SDK for interacting with the AccessGrid.com API. This SDK provides a simple interface for managing NFC key cards and enterprise templates. Full docs at https://www.accessgrid.com/docs

Installation

pip install accessgrid

Quick Start

from accessgrid import AccessGrid

account_id = os.environ.get('ACCOUNT_ID')
secret_key = os.environ.get('SECRET_KEY')

client = AccessGrid(account_id, secret_key)

API Reference

Access Cards

Provision a new card

card = client.access_cards.provision(
    card_template_id="0xd3adb00b5",
    employee_id="123456789",
    full_name="Employee name",
    email="employee@yourwebsite.com",
    phone_number="+19547212241",
    classification="full_time",
    start_date="2025-01-31T22:46:25.601Z",
    expiration_date="2025-04-30T22:46:25.601Z",
    employee_photo="[image_in_base64_encoded_format]"
)

Update a card

card = client.access_cards.update(
    card_id="0xc4rd1d",
    employee_id="987654321",
    full_name="Updated Employee Name",
    classification="contractor",
    expiration_date="2025-02-22T21:04:03.664Z",
    employee_photo="[image_in_base64_encoded_format]"
)

List NFC keys / Access passes

# List all cards for a template
cards = client.access_cards.list(template_id="0xd3adb00b5")
for card in cards:
    print(card)  # Outputs: AccessCard(name='Employee Name', id='0xc4rd1d', state='active')

# Filter cards by state
active_cards = client.access_cards.list(template_id="0xd3adb00b5", state="active")

Manage card states

# Suspend a card
client.access_cards.suspend(card_id="0xc4rd1d")

# Resume a card
client.access_cards.resume(card_id="0xc4rd1d")

# Unlink a card
client.access_cards.unlink(card_id="0xc4rd1d")

# Delete a card
client.access_cards.delete(card_id="0xc4rd1d")

Enterprise Console

Create a template

template = client.console.create_template(
    name="Employee NFC key",
    platform="apple",
    use_case="employee_badge",
    protocol="desfire",
    allow_on_multiple_devices=True,
    watch_count=2,
    iphone_count=3,
    design={
        "background_color": "#FFFFFF",
        "label_color": "#000000",
        "label_secondary_color": "#333333",
        "background_image": "[image_in_base64_encoded_format]",
        "logo_image": "[image_in_base64_encoded_format]",
        "icon_image": "[image_in_base64_encoded_format]"
    },
    support_info={
        "support_url": "https://help.yourcompany.com",
        "support_phone_number": "+1-555-123-4567",
        "support_email": "support@yourcompany.com",
        "privacy_policy_url": "https://yourcompany.com/privacy",
        "terms_and_conditions_url": "https://yourcompany.com/terms"
    }
)

Update a template

template = client.console.update_template(
    card_template_id="0xd3adb00b5",
    name="Updated Employee NFC key",
    allow_on_multiple_devices=True,
    watch_count=2,
    iphone_count=3,
    support_info={
        "support_url": "https://help.yourcompany.com",
        "support_phone_number": "+1-555-123-4567",
        "support_email": "support@yourcompany.com",
        "privacy_policy_url": "https://yourcompany.com/privacy",
        "terms_and_conditions_url": "https://yourcompany.com/terms"
    }
)

Read a template

template = client.console.read_template(card_template_id="0xd3adb00b5")

Get event logs

from datetime import datetime, timedelta

events = client.console.event_log(
    card_template_id="0xd3adb00b5",
    filters={
        "device": "mobile",  # "mobile" or "watch"
        "start_date": (datetime.now() - timedelta(days=30)).isoformat(),
        "end_date": datetime.now().isoformat(),
        "event_type": "install"
    }
)

Configuration

The SDK can be configured with custom options:

client = AccessGrid(
    account_id,
    secret_key
)

Error Handling

The SDK throws errors for various scenarios including:

  • Missing required credentials
  • API request failures
  • Invalid parameters
  • Server errors

Example error handling:

try:
    card = client.access_cards.provision(
        # ... parameters
    )
except AccessGridError as error:
    print(f'Failed to provision card: {str(error)}')

Requirements

  • Python 3.7 or higher
  • Required packages:
    • requests
    • cryptography
    • python-dateutil

Security

The SDK automatically handles:

  • Request signing using HMAC-SHA256
  • Secure payload encoding
  • Authentication headers
  • HTTPS communication

Never expose your secret_key in source code. Always use environment variables or a secure configuration management system.

License

MIT License - See LICENSE file for details.

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

accessgrid-0.1.7.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

accessgrid-0.1.7-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file accessgrid-0.1.7.tar.gz.

File metadata

  • Download URL: accessgrid-0.1.7.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for accessgrid-0.1.7.tar.gz
Algorithm Hash digest
SHA256 35d270d542a84cae963207962b972c0fe7673d1381c5490b110fa8a2b8f5bb78
MD5 1f358caaae89d3bd92d72276625e8979
BLAKE2b-256 87b3e0978536911d4876d825e0e3332564d6d7cc74df01a30d90aa1c4838faaa

See more details on using hashes here.

File details

Details for the file accessgrid-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: accessgrid-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for accessgrid-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b35d0abd3015c91839e09142e3ecf1c6bfaeb68e572f0db39b7943eb7d47d403
MD5 e3e08143b77a9019fa99b4ba87d81cf0
BLAKE2b-256 d6519ad5ec099ba9c487a2067fe86d31a18aa5839d559a47072b7d6d8e3de28c

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