# Need help on starting Python scripting



## Faynettius (Apr 11, 2018)

I I took at look at this and I wanted to know how to get started with Python scripting. Here's what I know, some questions,  and what I wanna do.

*What I know:*

There is an API for python scripting
*Questions:*

Where is the API library? Does it come with OBS or do I need to download it?
Where is the documentation for this API?
How do I get started with Scripting? 
Do I just import and go to work, or is there another file I need, or initialization steps that wouldn't be obvious from documentation?

*What I wanna do:*

Hide and un-hide specific images already on the overlay by reading from a text file
[If possible] Add an existing python GUI to the OBS GUI (Not Window Capture)
Read how long OBS has been recording (Which is shown in the OBS window, so I know it's somewhere)

Thanks in advance for any help.


----------



## dodgepong (Apr 11, 2018)

The Library comes with OBS. They are Python bindings for the OBS API. The documentation is here: https://obsproject.com/docs/

You'll find that in those docs there are a lot of C and C++ functions. Since the Python library provides bindings to these functions, there are virtually identical versions of these function calls in the Python library.

I recommend reading the Python script that ships with OBS to see an example of how Python scripting works: https://github.com/obsproject/obs-s...ugins/frontend-tools/data/scripts/url-text.py

For example, toward the top of that script, there is a call to obs.obs_get_source_by_name. That is a call to the Python binding to this function.

The main caveat to keep in mind is that since these are C/C++ bindings, you still have to do memory management manually, so you will need to free memory that you have allocated. Notice in the documentation that obs_get_source_by_name increments the reference counter, so before you end your script you will need to be sure to call obs_source_release() on the return value of obs_get_source_by_name.


----------



## Faynettius (Apr 11, 2018)

Thanks a lot! I'll get started with this, hopefully it won't be too difficult to work with, but it looks to be pretty straightforward, at least for my purposes.


----------



## maenuk (Mar 22, 2020)

Hi, I have a question about that.

Where can I find the keywords for the functions?

For Example:
In the ccript _url-text.py_ is the function _"obs.obs_data_set_string(settings, "text", text)"._

I found it in the doc:
              void obs_data_set_string(obs_data_t_ *data_, const char_ *name_, const char_ *val_) 

And where are the possible keywords for the parameter _const char *name  ("text") ?_

In an other script i found the function:
   obs.obs_data_set_int(s, "speed_percent", 200)
Where can I find the keyword "speed_percent" ?


----------



## vennet (Jul 23, 2020)

I am unable to import obspython library which is at the top of url-text.py. I tried installing that library but it says there is nothing like obspython.
I have few questions regarding python scripting:
1. What does url-text.py file do, does it help to stream from URL to destination like Youtube, Twitch, Facebook, etc, if yes how?
2. how to setup source for streaming?
3. How to install "obspython" library?
Thank You


----------



## dodgepong (Jul 23, 2020)

obspython is a library that only exists inside OBS. It's available if you run a script inside OBS. It's not something you install from PyPI.


----------



## vennet (Jul 24, 2020)

ok, I have never used this software before
How to run a python script inside OBS?
Thank You


----------



## vennet (Jul 24, 2020)

I added the script(url-text.py) to OBS via Tools -> Scripts -> + 
but what to do after that?
And what does url-text.py script do?


----------

