BunnyCDN is one of the fastest and most cost effective CDN.
With this BunnyCDN Python Library you can easily implement it and turbo charge your website content to deliver it at lighting speed to your visitors.
These instructions will let you install the bunnycdnpython python library running on your local machine.
Programming language: Python
version required : >=3.6
Python Library(s) required : requests library
pip install requests
OS : Any OS (ex: Windows , Mac , Linux)
Account : A account on -: (https://bunny.net/)
Step1: Open CMD
Step2: type
pip install bunnycdnpython
Now bunnycdnpython python library is installed
from BunnyCDN.Storage import Storage
from BunnyCDN.CDN import CDN
For using Storage API you have to initialize an object with your storage api key,storage zone name and storage zone region(optional)
obj_storage = Storage(storage_api_key,storage_zone_name,storage_zone_region)
For using Account API you have to initialize an object with your account api key
obj_cdn = CDN(account_api_key)
Storage module has functions that utilize APIs mentioned in official Bunnycdn storage apiary SA storage api documentation
To download a file from a storage zone to a particular path on your local server/PC
>>obj_storage.DownloadFile(storage_path,download_path(optional))
if download_path is not mentioned then file gets downloaded to current working directory
To upload a file to a specific directory in the storage zone
>>obj_storage.PutFile(file_name, storage_path=None, local_upload_file_path(optional) )
The storage_path here does not include storage zone name and it should end with the desired file name to be stored in storage zone.(example: ‘sample_dir/abc.txt’)
The local_upload_file_path is the path of the file in the local PC excluding file name
To delete a file or folder from a specific directory in storage zone
>>obj_storage.DeleteFile(storage_path)
If deleting a folder, make sure the storage_path ends with a trailing slash “/”.
Deleting a folder will delete all files within it.
Returns a list containing name of all the files and folders in the directory specified in storage path
>>obj_storage.GetStoragedObjectsList(storage_path)
CDN module has functions that utilize APIs mentioned in official Bunnycdn apiary CDN api documentation
To fetch the list of pullzones in the User’s Account
>>obj_cdn.GetPullZoneList()
To create a new Pulzone in User’s Account
>>obj_cdn.CreatePullZone(Name,OriginURL,Type,StorageZoneId (optional))
To return the pullzone details for the zone with the given ID
>>obj_cdn.GetPullZone(PullZoneID)
To update the pullzone with the given ID
>>obj_cdn.UpdatePullZone(PullZoneID,OriginUrl,AllowedReferrers,BlockedIps,EnableCacheSlice,EnableGeoZoneUS,EnableGeoZoneEU,EnableGeoZoneASIA,EnableGeoZoneSA,EnableGeoZoneAF,ZoneSecurityEnabled,ZoneSecurityIncludeHashRemoteIP,IgnoreQueryStrings,MonthlyBandwidthLimit,AccessControlOriginHeaderExtensions,EnableAccessControlOriginHeader,BlockRootPathAccess,EnableWebpVary,EnableHostnameVary,EnableCountryCodeVary,EnableLogging,DisableCookies,BudgetRedirectedCountries,BlockedCountries,EnableOriginShield,EnableQueryStringOrdering,CacheErrorResponses,OriginShieldZoneCode,AddCanonicalHeader,CacheControlMaxAgeOverride,AddHostHeader,AWSSigningEnabled,AWSSigningKey,AWSSigningRegionName,AWSSigningSecret,EnableTLS1,LoggingSaveToStorage,LoggingStorageZoneId,LogForwardingEnabled,LogForwardingHostname,LogForwardingPort,LogForwardingToken)
{
"status": "success",
"HTTP": 200,
"msg": "Update successful",
}
To delete the pullzone with the given ID
>>obj_cdn.DeletePullZone(PullZoneID)
{
"status": "success",
"HTTP": response.status_code,
"msg": "Successfully Deleted Pullzone",
}
To purge the full cache of given pullzone
>>obj_cdn.PurgePullZoneCache(PullZoneID)
```
To Add or Update an Edgerule of a particular Pullzone
>>obj_cdn.AddorUpdateEdgerule(PullZoneID,ActionParameter1,ActionParameter2,Enabled,Description,ActionType,TriggerMatchingType,Triggers,GUID(optional))
{
"status": "success",
"HTTP": 201,
"msg": "successfully updated edgerule ",
}
To Delete the pullzone with the given ID
>>obj_cdn.DeleteEdgeRule(PullZoneID,EdgeRuleID)
{
"status": "success",
"HTTP": 204,
"msg": "Successfully Deleted edgerule",
}
To add custom hostname to a pullzone
>>obj_cdn.AddCustomHostname(PullZoneID,Hostname)
{
"status": "success",
"HTTP": 200,
"msg": "Update was Successfull",
}
To delete custom hostname of a pullzone
>>obj_cdn.DeleteCustomHostname(PullZoneID,Hostname)
```
To enable or disable the ForceSSL setting for a pulzone
>>obj_cdn.SetForceSSL(PullZoneID,Hostname,ForceSSL)
{
"status": "success",
"HTTP": 200,
"msg": "successfully added Hostname ",
}
To Load a FREE SSL Certificate to the domain provided by Let’s Encrypt
>>obj_cdn.LoadFreeCertificate(self,Hostname)
[{"Name":"pullzone1","Id":"pullzoneid1"},{"Name":"pullzone2","Id":"pullzoneid2"}]
To Add a custom certificate to the given Pull Zone.
>>obj_cdn.AddCertificate(PullZoneId,Hostname,Certificate,CertificateKey)
{
"status": "success",
"HTTP": 200,
"msg": f"Certificated Added successfully Hostname:{Hostname}",
}
To add an IP to the list of blocked IPs that are not allowed to access the zone
>>obj_cdn.AddBlockedIp(PullZoneId, BlockedIp)
{
"status": "success",
"HTTP": 200,
"msg": "Ip successfully added to list of blocked IPs",
}
To removes mentioned IP from the list of blocked IPs that are not allowed to access the zone
>>obj_cdn.RemoveBlockedIp(PullZoneId, BlockedIp)
{
"status": "success",
"HTTP": 200,
"msg": "Ip removed from blocked IPs list "
}
Returns list of dictionaries containing storage zone name and its id
>>obj_cdn.StorageZoneList()
[{"Name":"storagezone1","Id":"storagezoneid1"},{"Name":"storagezone2","Id":"storagezoneid2"}]
Returns list of dictionaries containing details of storage zones in account
>>obj_cdn.StorageZoneData()
[
{
'Id': 53889,
'Storage_Zone_Name': 'mystoragezone1',
'Usage': 39080459,
'host_names': ['test.b-cdn.net', 'cdn.samplehostname.com'],
'PullZones': ['mypullzone1']
},
{
'Id': 54559,
'Storage_Zone_Name': 'mystoragezone2',
'Usage': 0,
'host_names': [],
'PullZones': ['mypullzone2']
}
]
This function creates an new storage zone
>>obj_cdn.AddStorageZone(storage_zone_name, storage_zone_region(optional),ReplicationRegions(optional))
{
"status": "success",
"HTTP": 201,
"msg": {
"Name": "mystoragezone",
"Region": "DE",
"ReplicationRegions": [
"NY",
"SG"
]
}
}
This function returns details about the storage zone with id:storage_zone_id
>>obj_cdn.GetStorageZone(storage_zone_id)
{
"Id": 4122,
"Name": "mystoragezone",
"Password": "storage-zone-password-key",
"ReadOnlyPassword": "storage-zone-password-key",
"UserId": "user-id",
"FilesStored": 20,
"StorageUsed": 1024,
"Deleted": false,
"DateModified": "2017-04-22T00:00:00Z"
}
Deletes the Storage Zone with the given ID
>>obj_cdn.DeleteStorageZone(storage_zone_id)
"status": "Success",
"HTTP": 201,
"msg": "Deleted Storagezone successfully",
}
Gets the details of Video Library of the specified id
>>obj_cdn.GetVideoLibrary(id)
```
This method deletes the Storage zone with id :storage_zone_id
>>obj_cdn.DeleteVideoLibrary(id)
{
"status": "success",
"HTTP": 201,
"msg": "Deleted Video Library"
}
This method purges the given URL from our edge server cache.
>>obj_cdn.PurgeUrlCache(url)
{
"status": "Success",
"HTTP": 200,
"msg": f"Purged Cache for url:{url}",
}
Returns the statistics associated with the account
>>obj_cdn.Stats(dateFrom=None,dateTo=None,pullZone=None,serverZoneId=None,loadErrors=True)
Here all the parameters are optional the method can also be called without any parameters
Returns the current billing summary of the account
>>obj_cdn.Billing()
Applies a promo code to the account
>>obj_cdn.ApplyCode( couponCode )
For the versions available, see the tags on this repository.
MATHIRITHMS - (https://mathrithms.com/)
##### 1. Aaditya Baranwal ##### 2. Joel Thomas
This project is licensed under the MIT License - see the LICENSE.md file for details
For any bugs or issue mail
- thomas.2@iitj.ac.in
- baranwal.1@iitj.ac.in