Obviously not just limited to fantasy. Politics is politics. How do you realistically handle things like trade deals, agreements, political marriages if it's relevant to the setting, industrialization, who fights who, things like that in your writing?
Personally, I think modern fantasy is a little too preoccupied with politics so I try to avoid it.
If I didn't though, I guess the only way to realistically portray it would be to learn about real-world politics and history and then to draw from that. Beyond that, it mostly boils down to character conflict: different characters will have goals, motivations and resources and those motives would then play off of each other.
All of the political stuff affects real people, many times in ways that are life-altering, with some people coming out for the better and others for the worse. Even the "boring" ones like a trade deal. If I was going to focus on the political intrigue, I would want to make sure I spent time with characters who were going to feel the full impact of what that political intrigue was about.
It depends on what you're doing with it. Is it mainly worldbuilding stuff which happens in the background or is it the heart of the story?
As for how to worldbuild it: consider a few things. What do the different factions want and what is the best way for them to get it? What leverage do the different sides have and what leverage does the other side thinks they have? Is there a third party involved? Also, consider that one side is not necessarily a unified faction. Maybe one party in your government wants the trade deal, while the other doesn't or maybe they want different terms. How do they go about getting that? What do people stand to gain and lose? I think that if it's important to the story, then this is one area where it pays to dig deeper. Ask why the different sides want what they want and who on their own side opposes them. And ask that a few times.
As for how to write it: Focus on the people performing the actions and the drama and on their interaction. Give the different sides a clear person who acts, instead of it just being "the purple party".
For instance, a political marriage. What does country A gain from the marriage and what does country B gain? Maybe country A wants to gain territory while country B needs a strong ally because they are being invaded by a third country. But at the same time, some people in country B don't want to lose their independence. Or in a trade deal. Maybe country A is smaller and weaker, but they have resources that everyone else wants. They need to please country B who is stronger so they don't get invaded. But at the same time they don't want to simply give away all their advantages. Or they try to play different countries against each other.
Its a lot of work, and it starts with your world building. The world you create needs to have demographical, geographical and geological features which explain how and why different nations arise in certain places. From this you can build up the nations, their power structures, their economies, trade routes and areas of common interest and conflicts of interest. Then the fun starts, because its at this point that the various instruments of power (politics, diplomacy, military action, economics etc) come into play.
Personally I sketch all this out in outline terms, if only because these factors will in some way affect my characters as thye move around. Most of the time they'll only see the low level stuff, things like money, inns along well travelled roads, harbours with ships sailing to other places, where to buy the best swords and why, and so on. Depending on how the story develops the characters may see other aspects, things like some form of postal or messenger services, the use of things like bills of exchange, the actions of some of the Kings high level officers. And all this may lead to situations where history, diplomacy and politics start to have an impact.
But it all starts with your world building. My advice, for what its worth, is to ensure you've sketched out the basics before you start writing, because retconning things after you've developed your story (or worse, stories) is very difficult.
This is going to be a big part of my second/third books and boy I am not looking forward to it. The political problems in my first book are all internal (these guys are mad at their government) and any external politics are in the past/offscreen and only serve as some (but not all) of the reasons for the internal stuff (how come stuff is better over there? Why can't we be that awesome? Also that past war was Really Bad and has made people from the "bad" country face a lot of discrimination that continues to today). The story is about a handful of characters, so my focus is on how these problems affect them and the conflicts that creates (guy who's from the Bad Guy species has to hide that fact, but his honor pushes him to out himself in order to stop the Bad Guy).
Since my world is filled with multiple sapient species and the core conflict is based on the schisms that inevitably forms due to their differences ("immortals" vs human life spans, can use magic vs cant etc), most of the politics/world building is based on that. Since there has only ever been 1 sapient species in recorded history*, all of that has to be speculative, but I can still draw upon reality in many ways. James Tullos has some really good videos about worldbuilding that have helped a lot.
One of the things that's important to keep in mind (and it always drives me nuts to see) is when every member of [x] does/thinks the exact same way. Everyone on the planet has the same religion, because it's 100% the right one, since those gods actually exist. Every elf is a vegan in a tree house. Ever orc is dumb, ugly and evil. People are individuals, so there is going to be variance even in a monoculture. Some of my Bad Guy species are evil, definitely, some are Very Good, but the majority of them are just people who want to take care of themselves and their families and not die. Some believe the war was justified, others think it's wrong, many don't have much of an opinion because it was so far away from them and didn't affect them all that much. Think about your friends who are in the same political party as you, there's probably different things they think are the most important issue, and there's different levels they're engaged in politics. A lot of epic stories ignore what the average person is doing or feeling and treats them as sheep, but that's really not the case.
*Neanderthals absolutely were sapient, and I'm sure some other hominids, but they were all pre-writing so it's difficult to know how exactly those things went, besides that there's Neanderthal DNA in a decent chunk of the world so we can make a few guesses there