Python Package for Social Network Analytics
The easiest way to install the latest version from PyPI is by using pip:
pip install pysna
You can also use Git to clone the repository from GitHub to install the latest development version:
git clone https://github.com/mathun3003/PySNA.git
cd PySNA
pip install .
Alternatively, install directly from the GitHub repository:
pip install git+https://github.com/mathun3003/PySNA.git
Import the API class for the Twitter API by writing:
from pysna import TwitterAPIor import utility functions, too, by writing:
from pysna import *Then, create an API instance by running:
api = TwitterAPI("BEARER_TOKEN", "CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET")and invoke a function:
api.user_info(...)Find usage and output examples in the examples folder.
This package was designed to perform data analysis on Twitter data. It extends the official Twitter API by using the open-source package tweepy.
Thus, the following functions are added to the tweepy package:
user_infotweet_infocompare_userscompare_tweets
Furthermore, some utility functions exist:
export_to_jsonappend_to_jsonload_from_jsonexport_to_csvappend_to_csv
You can find further information on the Documentation.
The above mentioned functions are also available on the CLI.
To see the usage instructions and help, run:
pysna -h
If you wish to see the usage instructions for a function, run:
pysna <function> --help
For example, if you want to request a comparison of two users, you can run:
pysna compare-users "WWU_Muenster" "goetheuni" -c "tweets_count" "common_followers" -o "results.json" --return-timestampThis will perform a comparison on the "WWU_Muenster" and "goetheuni" Twitter Accounts based on their number of composed Tweets and common followers. The results are exported to the results.json file. Also, the timestamp of the request will be returned.
NOTE: Every request needs valid credentials for the official Twitter API. Thus, pass in a .env file to every function call by using the --env flag or use the set-secrets function to set the API secrets for upcoming requests (recommended). See the corresponding section in the documentation.
- Only Python >= 3.10 is supported.
- Only
.envfiles are supported for the CLI, yet. - Use the
sample.local.envto ensure functionality of the CLI tool.