> ## 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

> Python PyPI client package for Ayrshare

## Overview

Ayrshare's [Social-Post-API PyPI Package](https://pypi.org/project/social-post-api/) allows you to integrate the Ayrshare API into your Python app.

### Installation

Install the [Social-Post-API PyPI Package](https://pypi.org/project/social-post-api/) if you use Python on the server-side. The package simplifies the calls by wrapping the RESTful calls.

Start by getting your secret API Key in [Ayrshare Dashboard](https://app.ayrshare.com/api).

Next, install the Python package:

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

### General Usage

Examples of Post, History, and Delete. Please see the [PyPI Package](https://pypi.org/project/social-post-api/) for more information.

<Info>
  **Posting to X/Twitter?** As of March 31, 2026, X/Twitter operations through Ayrshare require your own X Developer App credentials — Ayrshare enforces this on every X-bound call. Add the 2 BYO headers to your request. See the [setup guide](/dashboard/connect-social-accounts/x-twitter-byo-keys) for details.
</Info>

As of v1.3.0 the SDK includes a `set_twitter_byo(api_key, api_secret)` helper that attaches the two required `X-Twitter-OAuth1-*` headers to every subsequent request:

```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"]})
```

Use `clear_twitter_byo()` to drop the headers — useful when reusing one SDK instance across 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

You may specify the Profile Key for User Profile in the body of a POST or query of a GET with the `profileKey` field.

### More Information and Documentation

<ul class="custom-bullets">
  <li>[PyPI Package](https://pypi.org/project/social-post-api/)</li>
  <li>[Github Repository](https://github.com/ayrshare/social-post-api-python)</li>
  <li>[Issue Discussion](https://github.com/ayrshare/social-post-api-python/issues)</li>
</ul>
