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.
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:
pip install youtube-pydantic-models
Example usage
YoutubeClient
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
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
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
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
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.
Metadata
Release files for youtube-pydantic-models 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| youtube_pydantic_models-0.2.2.tar.gz | 12.8 kB | Without provenance | Details for youtube_pydantic_models-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| youtube_pydantic_models-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for youtube_pydantic_models-0.2.2-py3-none-any.whl |
Total release size: 25.5 kB
Release files / youtube_pydantic_models-0.2.2.tar.gz
| Download URL | youtube_pydantic_models-0.2.2.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6583c03498a6d99ebe00d63661a70482e126383bcc64224022cd4000af495aef
|
|
BLAKE2b-256 checksum How to use checksums |
56fc44a38bf9f765b4088d2cd1026e3544e4468938db2e99ded637456d570f4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / youtube_pydantic_models-0.2.2-py3-none-any.whl
| Download URL | youtube_pydantic_models-0.2.2-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f972ed4a2ccb614819b24ac4d8ef9a2f3b2749a777f31c5cdc4de9c69925d9c9
|
|
BLAKE2b-256 checksum How to use checksums |
fca42f996a19c5f03d2becb3fa6c30f5840ddaed9ac5748deb15415545235d8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Security for youtube-pydantic-models 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.