Skip to main content

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

Metadata

Release files for magic-admin 2.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magic-admin 2.5.0
File Size Uploaded
magic_admin-2.5.0.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for magic-admin 2.5.0
File Interpreter ABI Platform
magic_admin-2.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.6 kB

Release files / magic_admin-2.5.0.tar.gz

Download URL magic_admin-2.5.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
37907413696258bc3f34ddbde4504b56fb031dddc67ff99958ccada1fdc245dd
BLAKE2b-256 checksum
How to use checksums
acd905286fdfd952d4015db98dd1ffb0b10384ec2989dd5b5d685689bd2e0333
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / magic_admin-2.5.0-py3-none-any.whl

Download URL magic_admin-2.5.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
187df6250a99d4e39c95672eb10e7412bc89f3a8d1270de832f49c1ae8a73454
BLAKE2b-256 checksum
How to use checksums
701f30898a1040eff5a9ea5d1cc30d079381ab77c0e95451a429b2a0cb1a04a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

2.5.0 This release

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.0.1

2 release files

1.0.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page