This project has been archived by its maintainers, and is no longer receiving any updates.
django-tweets
Create and delete tweets in a Django project.
This packages takes the advantage of the tweepy functionalities to connect it to a Django Backend.
The tweets objects can have media files as well.
Set up
Twitter Account
- Make sure you have a Twitter account.
- Go to the Twitter Developer Portal.
- Create a Project and an App
- Make sure your App has read and write permissions.
- Genenerate the necessary secrets and token.
django-tweets
- Install from PyPI
python -m pip install django-tweets
- Add the package to your settins INSTALLED_APPS
INSTALLED_APPS = [
...
"django_tweets",
...
]
- Add the following settings to your Django project.
| Django setting | Description | Required |
|---|---|---|
| TWITTER_API_KEY | Twitter API OAuth 1.0a Consumer Key | Yes |
| TWITTER_API_KEY_SECRET | Twitter API OAuth 1.0a Consumer Secret | Yes |
| TWITTER_BEARER_TOKEN | Twitter API OAuth 2.0 Bearer Token / Access Token | Yes |
| TWITTER_ACCESS_TOKEN | Twitter API OAuth 1.0a Access Token | Yes |
| TWITTER_ACCESS_TOKEN_SECRET | Twitter API OAuth 1.0a Access Token Secret | Yes |
| DJANGO_TWEETS_SYNC_DELETE | Synchronize object deletion with Twitter API. This is activated by default. | No |
| TWITTER_USERNAME | Useful for accessing to the url of a Tweet object | No |
Example:
import os
from dotenv import load_dotenv
load_dotenv()
...
############################## django-tweets ##############################
# username
TWITTER_USERNAME = "django_tweets" # https://twitter.com/django_tweets
# Consumer Keys
TWITTER_API_KEY = os.environ.get("TWITTER_API_KEY")
TWITTER_API_KEY_SECRET = os.environ.get("TWITTER_API_KEY_SECRET")
# Authentication Tokens
TWITTER_BEARER_TOKEN = os.environ.get("TWITTER_BEARER_TOKEN")
TWITTER_ACCESS_TOKEN = os.environ.get("TWITTER_ACCESS_TOKEN")
TWITTER_ACCESS_TOKEN_SECRET = os.environ.get("TWITTER_ACCESS_TOKEN_SECRET")
# OAuth 2.0 Client ID and Client Secret
TWITTER_CLIENT_ID = os.environ.get("TWITTER_CLIENT_ID")
TWITTER_CLIENT_SECRET = os.environ.get("TWITTER_CLIENT_SECRET")
- Run migrations
python manage.py migrate
Usage
Create a simple tweet
from django_tweets.models import Tweet
# create a tweet in the db
tweet = Tweet.objects.create(text="Hi, this is my tweet using django-tweets and tweepy")
# publish it
tweet.publish()
Create a tweet with a media file
from pathlib import Path
from django.core.files.base import ContentFile
from django_tweets.models import Tweet, TweetFile
# create a media file
path = Path("path/to/my/file.jpg")
with open(path, "rb") as f:
f.seek(0)
contents = f.read()
tweet_file = TweetFile.objects.create(title="nice photo")
tweet_file.file.save(path.name, ContentFile(contents))
# upload to Twitter
tweet_file = tweet_file.upload()
# create a tweet in the db
tweet = Tweet.objects.create(text="My tweet with a file")
# add the media file to the tweet object
tweet.files.add(tweet_file)
# publish it
tweet.publish()
Usage in the admin
- Use http://127.0.0.1:8000/admin/django_tweets/tweet/ to create a Tweet object
- Use http://127.0.0.1:8000/admin/django_tweets/tweetpublication/ to link a Tweet object to publish it.
Similarly works with the TweetFile and TweetFileUpload models.
About
©Django is a registered trademark of the Django Software Foundation.
Metadata
Release files for django-tweets 0.0.9
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 |
|---|---|---|---|---|
| django-tweets-0.0.9.tar.gz | 9.8 kB | Without provenance | Details for django-tweets-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_tweets-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for django_tweets-0.0.9-py3-none-any.whl |
Total release size: 20.9 kB
Release files / django-tweets-0.0.9.tar.gz
| Download URL | django-tweets-0.0.9.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d0408785ef8ec005e48c7ae3621e58dc04890bed656d4a5e903c480c20f95b4
|
|
BLAKE2b-256 checksum How to use checksums |
cea299303ab7d5141e03962c34e4433bb91d310206e370d61cf33fdf761bd793
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
|
Release files / django_tweets-0.0.9-py3-none-any.whl
| Download URL | django_tweets-0.0.9-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bbcbd0ef8ecc95752c57cfbf0fc05dbb9444e1f4ac380693efa6c32defd44ab
|
|
BLAKE2b-256 checksum How to use checksums |
669a7b80cc2a7800a1ba5fcf6116c8c53ba324a6285620cab27c8247d12e8d6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
|
Security for django-tweets 0.0.9
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.