<commit_before>import shippo

#replace <API-KEY> with your key
shippo.api_key = "<API-KEY>"


#example address_from object dict
address_from = {
		"object_purpose":"PURCHASE",
		"name":"<NAME>",
		"company":"Shippo",
		"street1":"215 Clayton St.",
		"city":"San Francisco",
		"state":"CA",
		"zip":"94117",
		"country":"US", #iso2 country code
		"phone":"+1 555 341 9393",
		"email":"<EMAIL>",
       }

#example address_to object dict
address_to = {
		"object_purpose":"PURCHASE",
		"name":"<NAME>",
		"company":"London Zoo",
		"street1":"Regent's Park",
		"street2":"Outer Cir",
		"city":"LONDON",
		"state":"",
		"zip":"NW1 4RY",
		"country":"GB", #iso2 country code
		"phone":"+1 555 341 9393",
		"email":"<EMAIL>",
		"metadata" : "Hippos dont lie"
       	}

#parcel object dict
parcel = {
		"length":"5",
		"width":"5",
		"height":"5",
		"distance_unit":"in",
		"weight":"2",
		"mass_unit":"lb",
       	}

#example CustomsItems object. This is required for int'l shipment only.
customs_item = {
		"description":"T-Shirt",
		"quantity":2,
		"net_weight":"400",
		"mass_unit":"g",
		"value_amount":"20",
		"value_currency":"USD",
		"origin_country":"US",
		"tariff_number":"",
		}

#Creating the CustomsDeclaration
#(CustomsDeclaration are NOT required for domestic shipments)
customs_declaration = shippo.CustomsDeclaration.create(
		contents_type= 'MERCHANDISE',
		contents_explanation= 'T-Shirt purchase',
		non_delivery_option= 'RETURN',
		certify= True,
		certify_signer= '<NAME>',
		items= [customs_item])

#Creating the shipment object. In this example, the objects are directly passed to the 
#Shipment.create method, Alternatively, the Address and Parcel objects could be created 
#using Address.create(..) and Parcel.create(..) functions respectively.
shipment = shippo.Shipment.create(
		object_purpose= 'PURCHASE',
		address_from= address_from,
		address_to= address_to,
		parcel= parcel,
		submission_type= 'DROPOFF',
		customs_declaration=customs_declaration.object_id)

#Get all rates for shipment. sync=True indicates that the function will wait until all 
#rates are generated before it returns
rates = shippo.Shipment.get_rates(shipment.object_id, sync=True)

#Get the first rate in the rates results for demo purposes.
rate = rates.results[0]

#Purchase the desired rate. sync=True indicates that the function will wait until the 
#carrier returns a shipping label before it returns
transaction = shippo.Transaction.create(rate=rate.object_id, sync=True)

#print label_url and tracking_number
if transaction.object_status == "SUCCESS":
	print transaction.label_url
	print transaction.tracking_number
else :
	print transaction.messages<commit_msg>Updated examples with sync parameter, separate international example<commit_after>import shippo

#replace <API-KEY> with your key
shippo.api_key = "<API-KEY>"


###################
# Domestic Shipment
###################

#example address_from object dict
address_from = {
		"object_purpose":"PURCHASE",
		"name":"<NAME>",
		"company":"Shippo",
		"street1":"215 Clayton St.",
		"city":"San Francisco",
		"state":"CA",
		"zip":"94117",
		"country":"US", #iso2 country code
		"phone":"+1 555 341 9393",
		"email":"<EMAIL>",
       }

#example address_to object dict
address_to = {
		"object_purpose":"PURCHASE",
		"name":"<NAME>",
		"company":"",
		"street1":"Broadway 1",
		"street2":"",
		"city":"New York",
		"state":"NY",
		"zip":"10007",
		"country":"US",
		"phone":"+1 555 341 9393",
		"email":"<EMAIL>",
		"metadata" : "Hippos dont lie"
       	}

#parcel object dict
parcel = {
		"length":"5",
		"width":"5",
		"height":"5",
		"distance_unit":"in",
		"weight":"2",
		"mass_unit":"lb",
       	}

#Creating the shipment object. In this example, the objects are directly passed to the 
#Shipment.create method, Alternatively, the Address and Parcel objects could be created 
#using Address.create(..) and Parcel.create(..) functions respectively.
shipment = shippo.Shipment.create(
		object_purpose= 'PURCHASE',
		address_from= address_from,
		address_to= address_to,
		parcel= parcel,
		async= False )

#Get the first rate in the rates results for demo purposes.
rate = shipment.rates_list.results[0]

#Purchase the desired rate.
transaction = shippo.Transaction.create(rate=rate.object_id, async=False)

#print label_url and tracking_number
if transaction.object_status == "SUCCESS":
	print transaction.label_url
	print transaction.tracking_number
else :
	print transaction.messages


########################
# International Shipment
########################

#example address_to object dict
address_to_international = {
		"object_purpose":"PURCHASE",
		"name":"<NAME>",
		"company":"London Zoo",
		"street1":"Regent's Park",
		"street2":"Outer Cir",
		"city":"LONDON",
		"state":"",
		"zip":"NW1 4RY",
		"country":"GB", #iso2 country code
		"phone":"+1 555 341 9393",
		"email":"<EMAIL>",
		"metadata" : "Hippos dont lie"
       	}

#example CustomsItems object.
customs_item = {
		"description":"T-Shirt",
		"quantity":2,
		"net_weight":"400",
		"mass_unit":"g",
		"value_amount":"20",
		"value_currency":"USD",
		"origin_country":"US",
		"tariff_number":"",
		}

#Creating the CustomsDeclaration
customs_declaration = shippo.CustomsDeclaration.create(
		contents_type= 'MERCHANDISE',
		contents_explanation= 'T-Shirt purchase',
		non_delivery_option= 'RETURN',
		certify= True,
		certify_signer= '<NAME>',
		items= [customs_item],
		)

#Creating the shipment object. In this example, the objects are directly passed to the 
#Shipment.create method, Alternatively, the Address and Parcel objects could be created 
#using Address.create(..) and Parcel.create(..) functions respectively.
shipment_international = shippo.Shipment.create(
		object_purpose= 'PURCHASE',
		address_from= address_from,
		address_to= address_to_international,
		parcel= parcel,
		customs_declaration=customs_declaration.object_id,
		async= False )

#Get the first rate in the rates results for demo purposes.
rate_international = shipment_international.rates_list.results[0]

#Purchase the desired rate.
transaction_international = shippo.Transaction.create(rate=rate_international.object_id, async=False)

#print label_url and tracking_number
if transaction_international.object_status == "SUCCESS":
	print transaction_international.label_url
	print transaction_international.tracking_number
else :
	print transaction_international.messages

{'fraction_non_alphanumeric': 0.15103189493433397, 'fraction_numerical': 0.01813633520950594, 'mean_word_length': 5.321146245059288, 'pattern_counts': {'":': 84, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2033291', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2061, 'n_words': 528}