|
| 1 | +# API Keys |
| 2 | + |
| 3 | +To use the PyTally SDK, you need a Tally API key. This guide explains how to obtain and use your API key securely. |
| 4 | + |
| 5 | +## Getting Your API Key |
| 6 | + |
| 7 | +1. **Log in to Tally**: Go to [tally.so](https://tally.so) and sign in to your account |
| 8 | +2. **Navigate to Settings**: Click on your profile and select **Settings** |
| 9 | +3. **Access API Keys**: Go to the [API Keys](https://tally.so/settings/api-keys) section |
| 10 | +4. **Create New Key**: Click **"Create API key"** |
| 11 | +5. **Name Your Key**: Give your key a descriptive name (e.g., "Production App", "Development") |
| 12 | +6. **Copy the Key**: Copy the generated API key immediately - you won't be able to see it again! |
| 13 | + |
| 14 | +!!! warning "Keep Your API Key Secure" |
| 15 | +Your API key provides access to your Tally account and data. Never commit it to version control or share it publicly. |
| 16 | + |
| 17 | +## Using Your API Key |
| 18 | + |
| 19 | +### Basic Usage |
| 20 | + |
| 21 | +Pass your API key when initializing the client: |
| 22 | + |
| 23 | +```python |
| 24 | +from tally import Tally |
| 25 | + |
| 26 | +client = Tally(api_key="tly_your_api_key_here") |
| 27 | +``` |
| 28 | + |
| 29 | +### Environment Variables (Recommended) |
| 30 | + |
| 31 | +Store your API key in environment variables for better security: |
| 32 | + |
| 33 | +=== "Python" |
| 34 | + |
| 35 | + ```python |
| 36 | + import os |
| 37 | + from tally import Tally |
| 38 | + |
| 39 | + # Load API key from environment variable |
| 40 | + api_key = os.getenv("TALLY_API_KEY") |
| 41 | + client = Tally(api_key=api_key) |
| 42 | + ``` |
| 43 | + |
| 44 | +=== ".env File" |
| 45 | + |
| 46 | + Create a `.env` file in your project root: |
| 47 | + |
| 48 | + ```bash |
| 49 | + TALLY_API_KEY=tly_your_api_key_here |
| 50 | + ``` |
| 51 | + |
| 52 | + Then load it using `python-dotenv`: |
| 53 | + |
| 54 | + ```python |
| 55 | + from dotenv import load_dotenv |
| 56 | + import os |
| 57 | + from tally import Tally |
| 58 | + |
| 59 | + load_dotenv() |
| 60 | + |
| 61 | + client = Tally(api_key=os.getenv("TALLY_API_KEY")) |
| 62 | + ``` |
| 63 | + |
| 64 | +=== "Shell" |
| 65 | + |
| 66 | + Set the environment variable in your shell: |
| 67 | + |
| 68 | + ```bash |
| 69 | + # Linux/macOS |
| 70 | + export TALLY_API_KEY=tly_your_api_key_here |
| 71 | + |
| 72 | + # Windows (Command Prompt) |
| 73 | + set TALLY_API_KEY=tly_your_api_key_here |
| 74 | + |
| 75 | + # Windows (PowerShell) |
| 76 | + $env:TALLY_API_KEY="tly_your_api_key_here" |
| 77 | + ``` |
| 78 | + |
| 79 | +## Troubleshooting |
| 80 | + |
| 81 | +### Invalid API Key Error |
| 82 | + |
| 83 | +If you receive an [`UnauthorizedError`](error-handling.md#unauthorizederror-401): |
| 84 | + |
| 85 | +```python |
| 86 | +tally.exceptions.UnauthorizedError: Invalid API key |
| 87 | +``` |
| 88 | + |
| 89 | +**Solutions:** |
| 90 | + |
| 91 | +1. Verify the API key is correct (copy-paste from Tally dashboard) |
| 92 | +2. Check that you haven't accidentally included spaces or newlines |
| 93 | +3. Ensure the environment variable is properly loaded |
| 94 | +4. Verify the key hasn't been revoked in the Tally dashboard |
| 95 | + |
| 96 | +### Environment Variable Not Loading |
| 97 | + |
| 98 | +```python |
| 99 | +# Debug environment variables |
| 100 | +import os |
| 101 | +print(f"TALLY_API_KEY exists: {bool(os.getenv('TALLY_API_KEY'))}") |
| 102 | +print(f"TALLY_API_KEY value: {os.getenv('TALLY_API_KEY', 'NOT SET')}") |
| 103 | +``` |
| 104 | + |
| 105 | +## API Key Format |
| 106 | + |
| 107 | +Tally API keys follow this format: |
| 108 | + |
| 109 | +``` |
| 110 | +tly_<random_string> |
| 111 | +``` |
| 112 | + |
| 113 | +Example: `tly_abc123def456ghi789` |
| 114 | + |
| 115 | +## Next Steps |
| 116 | + |
| 117 | +- 📖 [API Reference](api-reference/users.md) - Explore available endpoints |
| 118 | +- ⚠️ [Error Handling](error-handling.md) - Handle authentication errors |
| 119 | +- 🏠 [Home](index.md) - Return to documentation home |
| 120 | + |
| 121 | +## Additional Resources |
| 122 | + |
| 123 | +- [Official Tally API Documentation](https://developers.tally.so/api-reference/introduction) |
| 124 | +- [Tally API Keys Dashboard](https://tally.so/settings/api-keys) |
0 commit comments