> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Python PyPI

> Package client Python PyPI pour Ayrshare

## Aperçu

Le [package PyPI Social-Post-API](https://pypi.org/project/social-post-api/) d'Ayrshare vous permet d'intégrer l'API Ayrshare dans votre application Python.

### Installation

Installez le [package PyPI Social-Post-API](https://pypi.org/project/social-post-api/) si vous utilisez Python côté serveur. Le package simplifie les appels en encapsulant les appels RESTful.

Commencez par obtenir votre API Key secrète dans le [tableau de bord Ayrshare](https://app.ayrshare.com/api).

Ensuite, installez le package Python :

```bash theme={"system"}
pip install social-post-api
```

### Utilisation générale

Exemples de Post, History et Delete. Veuillez consulter le [package PyPI](https://pypi.org/project/social-post-api/) pour plus d'informations.

<Info>
  **Vous publiez sur X/Twitter ?** À compter du 31 mars 2026, les opérations X/Twitter via Ayrshare nécessitent vos propres identifiants X Developer App — Ayrshare impose cette exigence pour chaque appel vers X. Ajoutez les 2 en-têtes BYO à votre requête. Consultez le [guide de configuration](/dashboard/connect-social-accounts/x-twitter-byo-keys) pour plus de détails.
</Info>

À partir de la v1.3.0, le SDK inclut un helper `set_twitter_byo(api_key, api_secret)` qui attache les deux en-têtes `X-Twitter-OAuth1-*` requis à chaque requête ultérieure :

```python theme={"system"}
from ayrshare import SocialPost

social = SocialPost(API_KEY)
social.set_twitter_byo(MY_X_API_KEY, MY_X_API_SECRET)

social.post({"post": "Hello from BYO", "platforms": ["twitter"]})
```

Utilisez `clear_twitter_byo()` pour supprimer les en-têtes — utile lors de la réutilisation d'une instance SDK entre différents tenants :

```python theme={"system"}
social.clear_twitter_byo().set_twitter_byo(next_tenant_key, next_tenant_secret)
```

```python theme={"system"}
from ayrshare import SocialPost
social = SocialPost('8jKj782Aw8910dCN') # get an API Key at ayrshare.com

# Required for any post that includes 'twitter' in platforms (BYO is enforced).
social.set_twitter_byo('YOUR_X_CONSUMER_KEY', 'YOUR_X_CONSUMER_SECRET')

# Post to Platforms Twitter, Facebook, and LinkedIn
postResult = social.post({'post': 'Nice Posting 2', 'platforms': ['twitter', 'facebook', 'linkedin'], 'profileKey': 'JKSDJI-JKKJKKJ'})
print(postResult)

# Delete (use the top-level Ayrshare post id from postResult['id'])
deleteResult = social.delete({'id': postResult['id']})
print(deleteResult)

# History
print(social.history())
```

### Profile Key

Vous pouvez spécifier la Profile Key pour un User Profile dans le corps d'un POST ou la requête d'un GET avec le champ `profileKey`.

### Plus d'informations et de documentation

<ul class="custom-bullets">
  <li>[Package PyPI](https://pypi.org/project/social-post-api/)</li>
  <li>[Dépôt Github](https://github.com/ayrshare/social-post-api-python)</li>
  <li>[Discussion des problèmes](https://github.com/ayrshare/social-post-api-python/issues)</li>
</ul>
