youtube-pydantic-models


Nameyoutube-pydantic-models JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryUse Pydantic models to work with the YouTube API.
upload_time2024-07-30 13:18:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT 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.
keywords youtube youtube-api youtubev3 youtube-v3 pydantic pydantic-model
VCS
bugtrack_url
requirements pydantic requests
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.  
Use the YoutubeClient class to get data about channels, playlists, videos and more.  
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)
- [**Docs**](https://fedeegmz.github.io/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
- Make requests to YouTube API using the client

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

### YoutubeClient

```python
from youtube_pydantic_models import YoutubeClient

client = YoutubeClient("MY_API_KEY")
channel = client.get_channel(
    id="UC_x5XG1OV2P6uZZ5FSM9Ttw",
    part="snippet, statistics"
)

if channel:
    print(channel.id) # -> UC_x5XG1OV2P6uZZ5FSM9Ttw
```

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "youtube-pydantic-models",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "youtube, youtube-api, youtubev3, youtube-v3, pydantic, pydantic-model",
    "author": null,
    "author_email": "Federico Gomez <gomez00federico@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/56/fc/44a38bf9f765b4088d2cd1026e3544e4468938db2e99ded637456d570f4f/youtube_pydantic_models-0.2.2.tar.gz",
    "platform": null,
    "description": "# youtube-pydantic-models\n\nA **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.  \nUse the YoutubeClient class to get data about channels, playlists, videos and more.  \nThe 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.\n\n- Author: [fedeegmz](https://github.com/fedeegmz)\n- Source: [GitHub](https://github.com/fedeegmz/youtube_pydantic_models)\n- [**Docs**](https://fedeegmz.github.io/youtube-pydantic-models/)\n\n## Features\n\n- Validate YouTube API responses using Pydantic models\n- Convert data between camel case and snake case\n- Easy-to-use interface for common YouTube resources\n- Make requests to YouTube API using the client\n\n## Requirements\n\n- Python 3.7+\n- A YouTube Data API Key\n\n## Installation\n\nYou can install the library using pip:\n\n```sh\npip install youtube-pydantic-models\n```\n\n## Example usage\n\n### YoutubeClient\n\n```python\nfrom youtube_pydantic_models import YoutubeClient\n\nclient = YoutubeClient(\"MY_API_KEY\")\nchannel = client.get_channel(\n    id=\"UC_x5XG1OV2P6uZZ5FSM9Ttw\",\n    part=\"snippet, statistics\"\n)\n\nif channel:\n    print(channel.id) # -> UC_x5XG1OV2P6uZZ5FSM9Ttw\n```\n\n### Channel Model\n\n```python\nimport requests\nfrom youtube_pydantic_models import YoutubeChannelResource\n\nparams = {\n    'id': \"UC_x5XG1OV2P6uZZ5FSM9Ttw\",\n    'key': \"YOUR_API_KEY\",\n    'part': \"snippet, contentDetails\"\n}\nresponse = requests.get(\n    \"https://www.googleapis.com/youtube/v3/channels\",\n    params=params\n).json()\n\nchannel = YoutubeChannelResource(**response)\nprint(channel.id)\nprint(channel.snippet.custom_url)\nchannel_dict = channel.model_dump(\n    by_alias=True,\n    exclude_none=True\n)\n```\n\n### Playlist Model\n\n```python\nimport requests\nfrom youtube_pydantic_models import YoutubePlaylistResource\n\nparams = {\n    'channelId': \"UC_x5XG1OV2P6uZZ5FSM9Ttw\",\n    'key': \"YOUR_API_KEY\",\n    'part': \"snippet, player\"\n}\nresponse = requests.get(\n    \"https://www.googleapis.com/youtube/v3/playlists\",\n    params=params\n).json()\n\nplaylist = YoutubePlaylistResource(**response)\nprint(playlist.snippet.channel_title)\nprint(playlist.player.embed_html)\nplaylist_dict = playlist.model_dump(\n    by_alias=True,\n    exclude_none=True\n)\n```\n\n### Video Model\n\n```python\nimport requests\nfrom youtube_pydantic_models import YoutubeVideoResource\n\nparams = {\n    'id': \"PJm8WNajZtw\",\n    'key': \"YOUR_API_KEY\",\n    'part': \"statistics\"\n}\nresponse = requests.get(\n    \"https://www.googleapis.com/youtube/v3/videos\",\n    params=params\n).json()\n\nvideo = YoutubeVideoResource(**response)\nprint(video.id)\nprint(video.statistics.view_count)\nvideo_dict = video.model_dump(\n    by_alias=True,\n    exclude_none=True\n)\n```\n\n### Search Model\n\n```python\nimport requests\nfrom youtube_pydantic_models import YoutubeSearchResource\n\nparams = {\n    'channelId': \"UC_x5XG1OV2P6uZZ5FSM9Ttw\",\n    'key': \"YOUR_API_KEY\",\n    'part': \"id, snippet\"\n}\nresponse = requests.get(\n    \"https://www.googleapis.com/youtube/v3/search\",\n    params=params\n).json()\n\nresource = YoutubeSearchResource(**response)\nprint(resource.id.kind)\nprint(resource.snippet.thumbnails.default.url)\nresource_dict = resource.model_dump(\n    by_alias=True,\n    exclude_none=True\n)\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request on GitHub.\n\n## License\n\nThis project is licensed under the MIT License.\n",
    "bugtrack_url": null,
    "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. ",
    "summary": "Use Pydantic models to work with the YouTube API.",
    "version": "0.2.2",
    "project_urls": {
        "Documentation": "https://fedeegmz.github.io/youtube-pydantic-models/",
        "Homepage": "https://github.com/fedeegmz/youtube-pydantic-models",
        "Issues": "https://github.com/fedeegmz/youtube-pydantic-models/issues"
    },
    "split_keywords": [
        "youtube",
        " youtube-api",
        " youtubev3",
        " youtube-v3",
        " pydantic",
        " pydantic-model"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fca42f996a19c5f03d2becb3fa6c30f5840ddaed9ac5748deb15415545235d8f",
                "md5": "0fb6a0e0ea2ecaa581854830d3c57c44",
                "sha256": "f972ed4a2ccb614819b24ac4d8ef9a2f3b2749a777f31c5cdc4de9c69925d9c9"
            },
            "downloads": -1,
            "filename": "youtube_pydantic_models-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0fb6a0e0ea2ecaa581854830d3c57c44",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 12690,
            "upload_time": "2024-07-30T13:18:52",
            "upload_time_iso_8601": "2024-07-30T13:18:52.421491Z",
            "url": "https://files.pythonhosted.org/packages/fc/a4/2f996a19c5f03d2becb3fa6c30f5840ddaed9ac5748deb15415545235d8f/youtube_pydantic_models-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56fc44a38bf9f765b4088d2cd1026e3544e4468938db2e99ded637456d570f4f",
                "md5": "299147656fa9aec550a66a4b8a10bf28",
                "sha256": "6583c03498a6d99ebe00d63661a70482e126383bcc64224022cd4000af495aef"
            },
            "downloads": -1,
            "filename": "youtube_pydantic_models-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "299147656fa9aec550a66a4b8a10bf28",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 12840,
            "upload_time": "2024-07-30T13:18:54",
            "upload_time_iso_8601": "2024-07-30T13:18:54.210443Z",
            "url": "https://files.pythonhosted.org/packages/56/fc/44a38bf9f765b4088d2cd1026e3544e4468938db2e99ded637456d570f4f/youtube_pydantic_models-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-30 13:18:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fedeegmz",
    "github_project": "youtube-pydantic-models",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pydantic",
            "specs": [
                [
                    "==",
                    "2.8.2"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.32.3"
                ]
            ]
        }
    ],
    "lcname": "youtube-pydantic-models"
}
        
Elapsed time: 2.89616s