Metadata-Version: 2.1
Name: python-tweet
Version: 0.2.0
Summary: A Python library for retrieving tweets from X (f.k.a. Twitter)
Author-email: Vladyslav Novotnyi <psejjkuczo@proxiedmail.com>
Maintainer-email: Vladyslav Novotnyi <psejjkuczo@proxiedmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2024 to present Vladyslav Novotnyi and individual contributors.
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/fabelx/py-tweet
Project-URL: Bug Reports, https://github.com/fabelx/py-tweet/issues
Project-URL: Source, https://github.com/fabelx/py-tweet
Keywords: twitter,x,tweet,api
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp
Requires-Dist: requests
Provides-Extra: dev
Requires-Dist: build ; extra == 'dev'
Requires-Dist: twine ; extra == 'dev'
Provides-Extra: lint
Requires-Dist: black ==23.12.0 ; extra == 'lint'
Requires-Dist: isort ==5.12.0 ; extra == 'lint'
Provides-Extra: pydantic
Requires-Dist: pydantic ; extra == 'pydantic'
Provides-Extra: test
Requires-Dist: pydantic ; extra == 'test'
Requires-Dist: coverage ; extra == 'test'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: pytest-asyncio ; extra == 'test'
Requires-Dist: pytest-cov ; extra == 'test'
Requires-Dist: gevent ; extra == 'test'

# Python Tweet

![PyPI - Version](https://img.shields.io/pypi/v/python-tweet?labelColor=%232e343b&label=pypi%20package)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/python-tweet?labelColor=%232e343b)
![PyPI - License](https://img.shields.io/pypi/l/python-tweet?labelColor=%232e343b)
[![Tests](https://github.com/fabelx/py-tweet/actions/workflows/tests.yml/badge.svg)](https://github.com/fabelx/py-tweet/actions/workflows/tests.yml)


## About
`pytweet` is a simple Python library with one goal: to retrieve tweet information from **X** for free.

_Inspired by [React-tweet](https://github.com/vercel/react-tweet) project._

### Key Feature
- doesn't require an [X](https://x.com/) (formerly known as **Twitter**) API token
___

## Installation
```bash
pip install python-tweet
```
From source:
```bash
make install
```
or
```bash
pip install .
```
___

## Usage
> ### It may cause conflicts with [PyTweet](https://pypi.org/project/PyTweet/) if you are using it in your project.

#### Async way:
```python
import asyncio
import json

from pytweet import get_tweet


async def main():
    tweet_id = "1803774806980022720"
    data = await get_tweet(tweet_id)
    with open(f"{tweet_id}.json", "w") as f:
        json.dump(data, f, indent=2)


if __name__ == '__main__':
    asyncio.run(main())

```

#### Sync way:
```python
import json

from pytweet.sync import get_tweet


def main():
    tweet_id = "1803774806980022720"
    data = get_tweet(tweet_id)
    with open(f"{tweet_id}.json", "w") as f:
        json.dump(data, f, indent=2)


if __name__ == '__main__':
    main()

```

#### Pydantic mode:
If you prefer working with object-oriented concepts, you may prefer receiving a class.
However, be aware that the returned JSON from [syndication](https://cdn.syndication.twimg.com/tweet-result) is undocumented, so errors or data loss may occur during conversion to a class.

Requires the installation of [pydantic](https://docs.pydantic.dev/latest/).
```bash
pip install python-tweet[pydantic]
```
```python
import asyncio
import json

from pytweet import get_tweet


async def main():
    tweet_id = "1803774806980022720"
    tweet = await get_tweet(tweet_id)
    with open(f"{tweet_id}.json", "w") as f:
        json.dump(tweet.model_dump(mode="json"), f, indent=2)


if __name__ == '__main__':
    asyncio.run(main())
```
If you are using Pydantic but want to receive a `dict`, pass the `as_dict` argument to the `get_tweet` function.
___

### To-do
- [x] Return a Tweet class instead a raw dict.
___

## License
`python-tweet` is released under the MIT License.
See the [LICENSE](https://github.com/fabelx/pycrossword/blob/main/LICENSE) file for license information.
