Skip to main content

Magic Python Library

Project description

Magic Admin Python SDK

Python 3.11+ PyPI version License

The Magic Admin Python SDK provides a simple and powerful way to integrate Magic's authentication system into your Python applications. Handle DID Tokens and interact with Magic API endpoints with ease.

📚 Documentation

📖 Full Documentation: Magic Python SDK Docs

🚀 Quick Start

Installation

# Using pip
pip install magic-admin

# Using uv
uv add magic-admin

Basic Usage

from magic_admin import Magic

# Initialize with your API secret key
magic = Magic(api_secret_key='your_api_secret_key_here')

# Validate a DID token
try:
    magic.Token.validate('DID_TOKEN_FROM_CLIENT')
    print("Token is valid!")
except Exception as e:
    print(f"Token validation failed: {e}")

Environment Variable Configuration

You can also load your API secret key from an environment variable:

export MAGIC_API_SECRET_KEY="your_api_secret_key_here"
from magic_admin import Magic

# Automatically uses MAGIC_API_SECRET_KEY environment variable
magic = Magic()

Note: The API secret key passed directly to Magic() takes precedence over the environment variable.

Network Configuration

Customize network behavior for your application:

magic = Magic(
    api_secret_key='your_key',
    retries=5,           # Number of retry attempts
    timeout=10,          # Request timeout in seconds
    backoff_factor=0.03  # Exponential backoff factor
)

🔧 Development

Prerequisites

  • Python 3.11+
  • Git

Setup Development Environment

# Clone the repository
git clone https://github.com/magiclabs/magic-admin-python.git
cd magic-admin-python

# Create virtual environment and install dependencies
make development

# Activate the virtual environment
source virtualenv_run/bin/activate

Running Tests

# Run tests against all supported Python versions (3.11, 3.12, 3.13)
make test

# Run tests with coverage
make test

Code Quality

This project uses pre-commit to maintain code quality. Hooks run automatically on every commit.

# Run pre-commit hooks manually
pre-commit run --all-files

# Install pre-commit hooks
pre-commit install

Cleanup

# Remove virtual environment, tox logs, and pytest cache
make clean

📋 Requirements

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: make test
  5. Run pre-commit: pre-commit run --all-files
  6. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

📝 Changelog

See CHANGELOG.md for a detailed history of changes.

🔗 Links

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

magic_admin-2.2.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

magic_admin-2.2.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file magic_admin-2.2.1.tar.gz.

File metadata

  • Download URL: magic_admin-2.2.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for magic_admin-2.2.1.tar.gz
Algorithm Hash digest
SHA256 04c9b53bbbf018f108214b71bad4ede317d225fc3fa9acb6301f3188e4475eec
MD5 9ccd120f9f12ab482d6a12e16e4b0ca6
BLAKE2b-256 ca7ad4ec30e6b6cb2bbe5307d9174e8a0c4de748efd7d39e11e670b2b128ca0e

See more details on using hashes here.

File details

Details for the file magic_admin-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: magic_admin-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for magic_admin-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f45976184b8239dbfb454c429a683359f562d16da8957a25ed5d3c3af08e1475
MD5 b8f2901aa751d5eaad5e3fbc955a31d7
BLAKE2b-256 dff0d62c27cf19091b7e5b21c243dead083b52febb9c3e78f685c4094c490113

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