Metadata-Version: 2.1
Name: youtube-pydantic-models
Version: 0.0.4
Summary: Work with Pydantic models when you are using YouTube API
Author-email: Federico Gomez <gomez00federico@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Federico Gomez
        
        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/fedeegmz/youtube_pydantic_models
Project-URL: Issues, https://github.com/fedeegmz/youtube_pydantic_models/issues
Keywords: youtube,youtube-api,youtubev3,youtube-v3,pydantic,pydantic-model
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic
Requires-Dist: google-api-python-client

# youtube-pydantic-models

A **Python** library that contains the most popular YouTube models based on Pydantic. If you are working with the **YouTube API**, **youtube-pydantic-models** can help you validate, manipulate, and retrieve data.  
The YouTube API returns data using camel case, but you can choose to return data using camel case or snake case. With the parameter ```by_alias=True```, data is returned using camel case.
When using the model, every parameter is accessed using snake case.

- Author: [**fedeegmz**](https://github.com/fedeegmz)
- Source: [**GitHub**](https://github.com/fedeegmz/youtube_pydantic_models)

## Features

- Validate YouTube API responses using Pydantic models
- Convert data between camel case and snake case
- Easy-to-use interface for common YouTube resources

## Requirements

- Python 3.7+
- A YouTube Data API Key

## Installation

You can install the library using pip:

```sh
pip install youtube-pydantic-models
```

## Example usage

### Channel Model

```python
import requests
from youtube_pydantic_models import YoutubeChannelResource

params = {
    'id': "UC_x5XG1OV2P6uZZ5FSM9Ttw",
    'key': "YOUR_API_KEY",
    'part': "snippet, contentDetails"
}
response = requests.get(
    "https://www.googleapis.com/youtube/v3/channels",
    params=params
).json()

channel = YoutubeChannelResource(**response)
print(channel.id)
print(channel.snippet.custom_url)
channel_dict = channel.model_dump(
    by_alias=True,
    exclude_none=True
)
```

### Playlist Model

```python
import requests
from youtube_pydantic_models import YoutubePlaylistResource

params = {
    'channelId': "UC_x5XG1OV2P6uZZ5FSM9Ttw",
    'key': "YOUR_API_KEY",
    'part': "snippet, player"
}
response = requests.get(
    "https://www.googleapis.com/youtube/v3/playlists",
    params=params
).json()

playlist = YoutubePlaylistResource(**response)
print(playlist.snippet.channel_title)
print(playlist.player.embed_html)
playlist_dict = playlist.model_dump(
    by_alias=True,
    exclude_none=True
)
```

### Video Model

```python
import requests
from youtube_pydantic_models import YoutubeVideoResource

params = {
    'id': "PJm8WNajZtw",
    'key': "YOUR_API_KEY",
    'part': "statistics"
}
response = requests.get(
    "https://www.googleapis.com/youtube/v3/videos",
    params=params
).json()

video = YoutubeVideoResource(**response)
print(video.id)
print(video.statistics.view_count)
video_dict = video.model_dump(
    by_alias=True,
    exclude_none=True
)
```

### Search Model

```python
import requests
from youtube_pydantic_models import YoutubeSearchResource

params = {
    'channelId': "UC_x5XG1OV2P6uZZ5FSM9Ttw",
    'key': "YOUR_API_KEY",
    'part': "id, snippet"
}
response = requests.get(
    "https://www.googleapis.com/youtube/v3/search",
    params=params
).json()

resource = YoutubeSearchResource(**response)
print(resource.id.kind)
print(resource.snippet.thumbnails.default.url)
resource_dict = resource.model_dump(
    by_alias=True,
    exclude_none=True
)
```

## Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

## License

This project is licensed under the MIT License.
