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.
📖 Full Documentation: Magic Python SDK Docs
# Using pip
pip install magic-admin
# Using uv
uv add magic-adminfrommagic_adminimportMagic# Initialize with your API secret keymagic=Magic(api_secret_key='your_api_secret_key_here')
# Validate a DID tokentry:
magic.Token.validate('DID_TOKEN_FROM_CLIENT')
print("Token is valid!")
exceptExceptionase:
print(f"Token validation failed: {e}")You can also load your API secret key from an environment variable:
export MAGIC_API_SECRET_KEY="your_api_secret_key_here"frommagic_adminimportMagic# Automatically uses MAGIC_API_SECRET_KEY environment variablemagic=Magic()Note: The API secret key passed directly to
Magic()takes precedence over the environment variable.
Customize network behavior for your application:
magic=Magic(
api_secret_key='your_key',
retries=5, # Number of retry attemptstimeout=10, # Request timeout in secondsbackoff_factor=0.03# Exponential backoff factor
)- Python 3.11+
- Git
# 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 environmentsource virtualenv_run/bin/activate# Run tests against all supported Python versions (3.11, 3.12, 3.13)
make test# Run tests with coverage
make testThis 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# Remove virtual environment, tox logs, and pytest cache
make clean- Python: 3.11+
- Dependencies: See requirements.txt
- Development: See requirements-dev.txt
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
make test - Run pre-commit:
pre-commit run --all-files - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for a detailed history of changes.